#read #write #combine #socket

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

#6 in #combine

Download history 309/week @ 2022-11-28 315/week @ 2022-12-05 347/week @ 2022-12-12 320/week @ 2022-12-19 142/week @ 2022-12-26 185/week @ 2023-01-02 270/week @ 2023-01-09 280/week @ 2023-01-16 254/week @ 2023-01-23 315/week @ 2023-01-30 256/week @ 2023-02-06 366/week @ 2023-02-13 406/week @ 2023-02-20 416/week @ 2023-02-27 428/week @ 2023-03-06 257/week @ 2023-03-13

1,540 downloads per month
Used in fewer than 9 crates

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

~140KB