Struct io_providers::SimulatedStdStreams[][src]

pub struct SimulatedStdStreams { /* fields omitted */ }

Simulated handles for the standard input streams of a process.

Simulated input can be provided using write_input(), and output can be observed using read_output() and read_error().

Methods

impl SimulatedStdStreams
[src]

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

Example

use io_providers::{StdStreams, SimulatedStdStreams};

let mut streams = SimulatedStdStreams::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::{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.

Example

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

Trait Implementations

impl Default for SimulatedStdStreams
[src]

Returns the "default value" for a type. Read more

impl StdStreams for SimulatedStdStreams
[src]

Gets the input stream.

Gets the output stream.

Gets the error stream.

Auto Trait Implementations