Struct io_providers::stream::Virtual [] [src]

pub struct Virtual { /* fields omitted */ }

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().

Methods

impl Virtual
[src]

Creates a new, empty virtual stream provider.

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"

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());

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());

Trait Implementations

impl Provider for Virtual
[src]

Gets the input stream.

Gets the output stream.

Gets the error stream.