5 unstable releases
0.3.0 | Dec 13, 2019 |
---|---|
0.2.0 | Sep 30, 2019 |
0.1.2 | Aug 30, 2019 |
0.1.1 | Aug 3, 2019 |
0.1.0 | Jul 28, 2019 |
#2063 in Asynchronous
128 downloads per month
Used in 3 crates
7KB
80 lines
merge-io
Merge two separate AsyncRead
and AsyncWrite
objects into a single I/O
stream.
lib.rs
:
Merge two separate AsyncRead
and
AsyncWrite
objects into a single I/O stream.
Examples
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]);
Dependencies
~19KB