pub struct Virtual { /* private fields */ }Expand description
Provides virtual input/output/error streams: input can be provided using
Virtual::write_input(), and output can be observed using Virtual::read_output() and
Virtual::read_error().
Implementations§
Source§impl Virtual
impl Virtual
Sourcepub fn write_input(&mut self, input: &[u8])
pub fn write_input(&mut self, input: &[u8])
Writes the provided buffer to the queue of buffers to be used when input is requested
from this provider using Provider::input().
In particular, this method does NOT append data to a continuous buffer which is consumed
by Provider::input(); rather, it enqueues a buffer which will be used for a SINGLE call
to Provider::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
Provider::input().
§Example
use io_providers::stream;
let mut streams = stream::Virtual::new();
streams.write_input("foo".as_bytes());
streams.write_input("bar".as_bytes());
// The first read on `streams.input()` will read from "foo"
// The second read on `streams.input()` will read from "bar"Sourcepub fn read_output<'a>(&'a self) -> &'a [u8] ⓘ
pub fn read_output<'a>(&'a self) -> &'a [u8] ⓘ
Gets the data which has been written to the output stream.
§Example
use std::io::Write;
use io_providers::stream;
use io_providers::stream::Provider;
let mut streams = stream::Virtual::new();
writeln!(streams.output(), "test1");
write!(streams.output(), "test2");
assert_eq!("test1\ntest2", ::std::str::from_utf8(streams.read_output()).unwrap());Sourcepub fn read_error<'a>(&'a self) -> &'a [u8] ⓘ
pub fn read_error<'a>(&'a self) -> &'a [u8] ⓘ
Gets the data which has been written to error stream.
§Example
use std::io::Write;
use io_providers::stream;
use io_providers::stream::Provider;
let mut streams = stream::Virtual::new();
writeln!(streams.error(), "test1");
write!(streams.error(), "test2");
assert_eq!("test1\ntest2", ::std::str::from_utf8(streams.read_error()).unwrap());