futures_util::stream

Function once

Source
pub fn once<F: IntoFuture>(item: F) -> Once<F::Future>
Expand description

Creates a stream of single element

use futures::prelude::*;
use futures::stream;
use futures_executor::block_on;

let mut stream = stream::once::<Result<(), _>>(Err(17));
let collected: Result<Vec<_>, _> = block_on(stream.collect());
assert_eq!(collected, Err(17));

let mut stream = stream::once::<Result<_, ()>>(Ok(92));
let collected: Result<Vec<_>, _> = block_on(stream.collect());
assert_eq!(collected, Ok(vec![92]));