pub fn iter_result<J, T, E>(i: J) -> IterResult<<J as IntoIterator>::IntoIter>where
J: IntoIterator<Item = Result<T, E>>,
Expand description
Converts an Iterator
over Result
s into a Stream
which is always ready
to yield the next value.
Iterators in Rust don’t express the ability to block, so this adapter simply
always calls iter.next()
and returns that.
use futures::prelude::*;
use futures::stream;
use futures_executor::block_on;
let mut stream = stream::iter_result(vec![Ok(17), Err(false), Ok(19)]);
let (item, stream) = block_on(stream.next()).unwrap();
assert_eq!(Some(17), item);
let (err, stream) = block_on(stream.next()).unwrap_err();
assert_eq!(false, err);
let (item, stream) = block_on(stream.next()).unwrap();
assert_eq!(Some(19), item);
let (item, _) = block_on(stream.next()).unwrap();
assert_eq!(None, item);