https://github.com/vi/readwrite
Rust mini-library to combine a reader and a writer into a Read+Write psedo-socket.
https://github.com/vi/readwrite
Last synced: about 1 year ago
JSON representation
Rust mini-library to combine a reader and a writer into a Read+Write psedo-socket.
- Host: GitHub
- URL: https://github.com/vi/readwrite
- Owner: vi
- License: apache-2.0
- Created: 2018-08-18T19:01:16.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-03-08T00:23:14.000Z (over 5 years ago)
- Last Synced: 2025-03-28T21:02:37.245Z (over 1 year ago)
- Language: Rust
- Size: 13.7 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE-2.0
Awesome Lists containing this project
README
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.
```rust
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](https://github.com/async-rs/duplexify) - alternative implementation for async-std
* Use version `0.1` of this crate for old `tokio-core` support. `tokio 0.1` is not supported.