[][src]Crate merge_io

Merge two separate AsyncRead and AsyncWrite objects into a single I/O stream.


use merge_io::MergeIO;
use futures::io::Cursor;
use futures::{AsyncReadExt, AsyncWriteExt};

// Prepare `reader` to read data from...
let reader = Cursor::new(vec![1, 2, 3, 4]);

// ... and `writer` to read data to.
let writer: Vec<u8> = vec![];

// Merge `reader` and `writer` into a single I/O stream.
let mut stream = MergeIO::new(reader, writer);

// Read data from stream.
let mut read_buf = Vec::<u8>::with_capacity(1024);
stream.read_to_end(&mut read_buf).await?;

// We got what was in the `reader`!
assert_eq!(&read_buf, &[1, 2, 3, 4]);

// Write data to stream.
stream.write_all(&[10, 20, 30, 40]).await?;

// `writer` now contains what we wrote!
assert_eq!(stream.writer(), &[10, 20, 30, 40]);



Merged I/O, delegates reads and writes to the provided AsyncRead (R) and AsyncWrite (W).