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§
Sourcefn override_stdout(&self) -> Result<Guard>
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");Sourcefn override_stderr(&self) -> Result<Guard>
fn override_stderr(&self) -> Result<Guard>
Replace the process standard error with a duplicate of the file descriptor.
See duplicate_to_stdout.
Sourcefn override_stdin(&self) -> Result<Guard>
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!");