#combine #io-read #async-io #io-write #tokio #write #read

readwrite

Combine Read and Write into a single Read+Write object

4 releases

0.2.0 Mar 8, 2021
0.1.2 May 4, 2020
0.1.1 Aug 18, 2018
0.1.0 Aug 18, 2018

#15 in #combine

Download history 343/week @ 2024-06-13 470/week @ 2024-06-20 355/week @ 2024-06-27 426/week @ 2024-07-04 412/week @ 2024-07-11 391/week @ 2024-07-18 377/week @ 2024-07-25 357/week @ 2024-08-01 417/week @ 2024-08-08 281/week @ 2024-08-15 239/week @ 2024-08-22 323/week @ 2024-08-29 397/week @ 2024-09-05 315/week @ 2024-09-12 378/week @ 2024-09-19 385/week @ 2024-09-26

1,530 downloads per month
Used in 11 crates (10 directly)

MIT/Apache

14KB
268 lines

readwrite

Given two things, one of which implements std::io::Read and other implements std::io::Write, make a single socket-like object which implements Read + Write. Note that you can't write to it while waiting for data to come from read part.

Example: generate a virtual socketpair.

fn main() {
    extern crate pipe;
    extern crate readwrite;

    let (r1,w1) = pipe::pipe();
    let (r2,w2) = pipe::pipe();
    let (s1,s2) = (ReadWrite::new(r1,w2), ReadWrite::new(r2,w1));
}

There is also async implementation for combining tokio::io::AsyncRead and tokio::io::AsyncWrite into a AsyncRead + AsyncWrite. Enable the non-default tokio Cargo feature for it to work: Similarly there is futures::io::AsyncRead/AsyncWrite version gated under asyncstd Cargo feature.

[dependencies]
readwrite = {version="0.1.1", features=["tokio"]}

See also

  • duplexify - alternative implementation for async-std
  • Use version 0.1 of this crate for old tokio-core support. tokio 0.1 is not supported.

Dependencies

~0–5.5MB
~22K SLoC