#io-stream #io #async-io #async #merge #async-read #async-write

merge-io

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

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

Download history 39/week @ 2024-08-26 29/week @ 2024-09-02 38/week @ 2024-09-09 43/week @ 2024-09-16 66/week @ 2024-09-23 41/week @ 2024-09-30 10/week @ 2024-10-07 71/week @ 2024-10-14 1/week @ 2024-10-21 18/week @ 2024-10-28 16/week @ 2024-11-04 7/week @ 2024-11-11 36/week @ 2024-11-18 19/week @ 2024-11-25 18/week @ 2024-12-02 54/week @ 2024-12-09

128 downloads per month
Used in 3 crates

MIT license

7KB
80 lines

merge-io

Build Status Crates.io Documentation

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

Documentation


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