1 #![deprecated(note = "implementation moved to `iter_ok` and `iter_result`")]
2 #![allow(deprecated)]
3
4 use Poll;
5 use stream::{iter_result, IterResult, Stream};
6
7 /// A stream which is just a shim over an underlying instance of `Iterator`.
8 ///
9 /// This stream will never block and is always ready.
10 #[derive(Debug)]
11 #[must_use = "streams do nothing unless polled"]
12 pub struct Iter<I>(IterResult<I>);
13
14 /// Converts an `Iterator` over `Result`s into a `Stream` which is always ready
15 /// to yield the next value.
16 ///
17 /// Iterators in Rust don't express the ability to block, so this adapter simply
18 /// always calls `iter.next()` and returns that.
19 ///
20 /// ```rust
21 /// use futures::*;
22 ///
23 /// let mut stream = stream::iter(vec![Ok(17), Err(false), Ok(19)]);
24 /// assert_eq!(Ok(Async::Ready(Some(17))), stream.poll());
25 /// assert_eq!(Err(false), stream.poll());
26 /// assert_eq!(Ok(Async::Ready(Some(19))), stream.poll());
27 /// assert_eq!(Ok(Async::Ready(None)), stream.poll());
28 /// ```
29 #[inline]
iter<J, T, E>(i: J) -> Iter<J::IntoIter> where J: IntoIterator<Item=Result<T, E>>,30 pub fn iter<J, T, E>(i: J) -> Iter<J::IntoIter>
31 where J: IntoIterator<Item=Result<T, E>>,
32 {
33 Iter(iter_result(i))
34 }
35
36 impl<I, T, E> Stream for Iter<I>
37 where I: Iterator<Item=Result<T, E>>,
38 {
39 type Item = T;
40 type Error = E;
41
42 #[inline]
poll(&mut self) -> Poll<Option<T>, E>43 fn poll(&mut self) -> Poll<Option<T>, E> {
44 self.0.poll()
45 }
46 }
47