[][src]Function tokio::stream::once

pub fn once<T>(value: T) -> Once<T>
This is supported on crate feature stream only.

Creates a stream that emits an element exactly once.

The returned stream is immediately ready and emits the provided value once.

Examples

use tokio::stream::{self, StreamExt};

#[tokio::main]
async fn main() {
    // one is the loneliest number
    let mut one = stream::once(1);

    assert_eq!(Some(1), one.next().await);

    // just one, that's all we get
    assert_eq!(None, one.next().await);
}