Crate transform_stream

Source
Expand description

Lightweight async stream wrapper.

Inspired by https://github.com/tokio-rs/async-stream

§Usage

use transform_stream::{try_stream, AsyncTryStream};
use futures_util::{pin_mut, StreamExt};
use std::io;

let stream: AsyncTryStream<Vec<u8>, io::Error, _> = try_stream!{
    yield_!(vec![b'1', b'2']);
    yield_!(vec![b'3', b'4']);
    Ok(())
};

futures_executor::block_on(async {
    pin_mut!(stream);
    assert_eq!(stream.next().await.unwrap().unwrap(), vec![b'1', b'2']);
    assert_eq!(stream.next().await.unwrap().unwrap(), vec![b'3', b'4']);
    assert!(stream.next().await.is_none());
});

Macros§

stream
Create a new stream
try_stream
Create a new try stream

Structs§

AsyncStream
Asynchronous stream of items
AsyncTryStream
Asynchronous stream of results
Yielder
A handle for sending items into the related stream.