#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

#2043 in Asynchronous

Download history 14/week @ 2024-07-20 40/week @ 2024-07-27 35/week @ 2024-08-03 27/week @ 2024-08-10 31/week @ 2024-08-17 32/week @ 2024-08-24 34/week @ 2024-08-31 39/week @ 2024-09-07 44/week @ 2024-09-14 58/week @ 2024-09-21 50/week @ 2024-09-28 11/week @ 2024-10-05 69/week @ 2024-10-12 4/week @ 2024-10-19 15/week @ 2024-10-26 8/week @ 2024-11-02

99 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