2 #![allow(unused_must_use)]
8 let rx = Err::<Vec<usize>, u32>(1).into_future();
10 rx.map(|l: Vec<usize>| stream::iter(l.into_iter().map(|i| Ok(i))))
16 use future::{Future, IntoFuture};
26 fn map<F, U>(self, _: F) -> Map<Self, F>
27 where F: FnOnce(Self::Item) -> U,
33 fn flatten_stream(self) -> FlattenStream<Self>
34 where <Self as Future>::Item: stream::Stream<Error=Self::Error>,
41 pub trait IntoFuture {
42 type Future: Future<Item=Self::Item, Error=Self::Error>;
45 fn into_future(self) -> Self::Future;
48 impl<F: Future> IntoFuture for F {
51 type Error = F::Error;
53 fn into_future(self) -> F {
58 impl<T, E> IntoFuture for result::Result<T, E> {
59 type Future = FutureResult<T, E>;
63 fn into_future(self) -> FutureResult<T, E> {
68 pub struct Map<A, F> {
72 impl<U, A, F> Future for Map<A, F>
74 F: FnOnce(A::Item) -> U,
77 type Error = A::Error;
80 pub struct FlattenStream<F> {
84 impl<F> Stream for FlattenStream<F>
86 <F as Future>::Item: Stream<Error=F::Error>,
88 type Item = <F::Item as Stream>::Item;
89 type Error = <F::Item as Stream>::Error;
92 pub struct FutureResult<T, E> {
96 impl<T, E> Future for FutureResult<T, E> {
109 fn buffer_unordered(self, amt: usize) -> BufferUnordered<Self>
110 where Self::Item: IntoFuture<Error = <Self as Stream>::Error>,
116 fn chunks(self, _capacity: usize) -> Chunks<Self>
123 pub struct IterStream<I> {
127 pub fn iter<J, T, E>(_: J) -> IterStream<J::IntoIter>
128 where J: IntoIterator<Item=Result<T, E>>,
133 impl<I, T, E> Stream for IterStream<I>
134 where I: Iterator<Item=Result<T, E>>,
140 pub struct Chunks<S> {
144 impl<S> Stream for Chunks<S>
147 type Item = Result<Vec<<S as Stream>::Item>, u32>;
148 type Error = <S as Stream>::Error;
151 pub struct BufferUnordered<S> {
156 Next(#[allow(unused_tuple_struct_fields)] usize),
160 fn new<S>(_s: S, _amt: usize) -> BufferUnordered<S>
162 S::Item: IntoFuture<Error=<S as Stream>::Error>,
165 Slot::Next::<<S::Item as IntoFuture>::Future>(1)
166 }).collect::<Vec<_>>();
170 impl<S> Stream for BufferUnordered<S>
172 S::Item: IntoFuture<Error=<S as Stream>::Error>,
174 type Item = <S::Item as IntoFuture>::Item;
175 type Error = <S as Stream>::Error;