Skip to main content

ReadWrite

Trait ReadWrite 

Source
pub trait ReadWrite: Read + Write { }
Expand description

Object-safe capability trait for values that can be both read and written.

ReadWrite gives the common Read + Write combination a named trait for APIs that work with duplex streams or mutable buffers through trait objects. Typical use cases include protocol handlers, in-memory transport tests, and adapters that should not care about the concrete stream type.

The trait adds no methods of its own. All operations come from the standard-library supertraits, and every type implementing both Read and Write automatically implements ReadWrite.

§Examples

use qubit_io::ReadWrite;

fn send_ping(stream: &mut dyn ReadWrite) -> std::io::Result<()> {
    stream.write_all(b"ping")
}

let mut cursor = std::io::Cursor::new(Vec::new());
send_ping(&mut cursor)?;
assert_eq!(cursor.into_inner(), b"ping");

Implementors§

Source§

impl<T> ReadWrite for T
where T: Read + Write,