Trait StdioOverride

Source
pub trait StdioOverride: AsFd {
    // Provided methods
    fn override_stdout(&self) -> Result<Guard> { ... }
    fn override_stderr(&self) -> Result<Guard> { ... }
    fn override_stdin(&self) -> Result<Guard> { ... }
}

Provided Methods§

Source

fn override_stdout(&self) -> Result<Guard>

Replace the process standard output with a duplicate of the file descriptor.

let _guard = File::create("./output.txt")?.override_stdout()?;
println!("hello world!");
let output = read_to_string("./output.txt")?;
assert_eq!(output, "hello world!\n");
Source

fn override_stderr(&self) -> Result<Guard>

Replace the process standard error with a duplicate of the file descriptor.

See duplicate_to_stdout.

Source

fn override_stdin(&self) -> Result<Guard>

Replace the process standard input with a duplicate of the file descriptor.

write("./input.txt", "hello world!")?;
let _guard = File::open("./input.txt")?.override_stdin()?;
let input = read_to_string(stdin())?;
assert_eq!(input, "hello world!");

Implementors§