Trait ReadWritePipe

Source
pub trait ReadWritePipe: Write {
    // Provided method
    fn write_reader<R: Read>(&mut self, r: R) -> Result<usize> { ... }
}
Expand description

A trait for objects implementing Write, to write all content from a Read object.

This trait adds one method to the writers implementing it.

  • write_reader This method allows to read a whole reader object into the writer. There is no garantee about the state of both reader and writer in case of an error.
use std::io;
use read_write_pipe::*;
let _ = io::stdout().write_reader(io::stdin()).unwrap();

Provided Methods§

Source

fn write_reader<R: Read>(&mut self, r: R) -> Result<usize>

Examples found in repository?
examples/simple_cat.rs (line 5)
4fn main() -> io::Result<()> {
5    let _ = io::stdout().write_reader(io::stdin())?;
6    Ok(())
7}
More examples
Hide additional examples
examples/copy_file.rs (line 23)
15fn main() -> io::Result<()> {
16    prepare_input()?;
17    let input = File::open("a.txt")?;
18    let mut output = OpenOptions::new()
19        .read(true)
20        .write(true)
21        .create(true)
22        .open("b.txt")?;
23    let _ = output.write_reader(input)?;
24    Ok(())
25}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§