pub struct SimulatedStdStreams { /* fields omitted */ }
Creates a new SimulatedStdStreams
.
Writes the provided buffer to the queue of buffers to be used when input is requested
using StdStreams::input()
.
In particular, this method does NOT append data to a continuous buffer which is consumed
by StdStreams::input()
; rather, it enqueues a buffer which will be used for a SINGLE
call to StdStreams::input()
. The buffer is then discarded, regardless of how much of it
was (or was not) read.
This enables precise control over the length of data returned from a call to
StdStreams::input()
.
use io_providers::{StdStreams, SimulatedStdStreams};
let mut streams = SimulatedStdStreams::new();
streams.write_input("foo".as_bytes());
streams.write_input("bar".as_bytes());
Gets the data which has been written to the output stream.
use std::io::Write;
use io_providers::{StdStreams, SimulatedStdStreams};
let mut streams = SimulatedStdStreams::new();
writeln!(streams.output(), "test1");
write!(streams.output(), "test2");
assert_eq!("test1\ntest2", ::std::str::from_utf8(streams.read_output()).unwrap());
Gets the data which has been written to the error stream.
use std::io::Write;
use io_providers::{StdStreams, SimulatedStdStreams};
let mut streams = SimulatedStdStreams::new();
writeln!(streams.error(), "test1");
write!(streams.error(), "test2");
assert_eq!("test1\ntest2", ::std::str::from_utf8(streams.read_error()).unwrap());
Returns the "default value" for a type. Read more