#io

duplex

The Duplex trait: interactive streams

13 breaking releases

0.13.0 Jun 16, 2022
0.12.0 Mar 16, 2022
0.11.0 Feb 1, 2022
0.10.0 Dec 24, 2021
0.3.1 Mar 4, 2021

#1046 in Rust patterns

Download history 18/week @ 2022-04-20 97/week @ 2022-04-27 108/week @ 2022-05-04 257/week @ 2022-05-11 81/week @ 2022-05-18 104/week @ 2022-05-25 142/week @ 2022-06-01 56/week @ 2022-06-08 117/week @ 2022-06-15 74/week @ 2022-06-22 28/week @ 2022-06-29 38/week @ 2022-07-06 131/week @ 2022-07-13 54/week @ 2022-07-20 56/week @ 2022-07-27 72/week @ 2022-08-03

317 downloads per month
Used in 8 crates (7 directly)

Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT

15KB
63 lines

duplex

The Duplex trait: interactive streams

Github Actions CI Status crates.io page docs.rs docs

This crate defines the Duplex trait, for types that have logically independent input and output channels.

The Read and Write traits take their streams by &mut self and block, so they cannot be used on the same stream simultaneously. This crate provides and implements the HalfDuplex trait for any type which implements Duplex, Read, and Write.

The AsyncRead and AsyncWrite traits take their streams by &mut self but do not block, so they can be used on the same stream simultaneously, at least when they're connected to an endpoint which supports it. When the "futures-io" feature is enabled, this crate provides and implements the FullDuplex trait for any type which implements Duplex, AsyncRead, and AsyncWrite.

Tokio uses its own AsyncRead, and AsyncWrite. When the "tokio" feature is enabled, this crate also provides and implements TokioFullDuplex for any type which implements Duplex, tokio::io::AsyncRead, and tokio::io::AsyncWrite.

Normal Files are not duplex devices, because even though they support input and output, the input and output are not logically independent since they share a current-position pointer in the OS. Character devices are often unified with files in OS APIs, however they may represent duplex devices. So while File does not implement Duplex, CharDevice does.

The following are some notable types for which Duplex is implemented:

Type cfg Notes
std::net::TcpStream
io_streams::StreamDuplexer
nameless::DuplexByteStream
nameless::DuplexTextStream
char_device::CharDevice feature = char-device
socketpair::SocketpairStream feature = socketpair
ssh2::Stream feature = ssh2
ssh2::Channel feature = ssh2
serialport::TTYPort all(unix, feature = serialport) serialport dependencies
readwrite::ReadWrite feature = readwrite
duplexify::Duplexify feature = duplexify
socket2::Socket feature = socket2

Dependencies

~0–8MB
~147K SLoC