#async

transform-stream

Lightweight async stream wrapper

3 releases

0.1.2 Oct 22, 2020
0.1.1 Oct 4, 2020
0.1.0 Oct 3, 2020

#291 in Asynchronous

MIT license

16KB
391 lines

transform-stream

Crates.io MIT licensed Docs CI Unsafe Forbidden

Lightweight async stream wrapper.

Usage

use transform_stream::{try_stream, AsyncTryStream};
use futures::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 {
    futures::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());
});

Dependencies

~105KB