io-providers
Defines "provider" traits and implementations for different types of I/O operations, enabling dependency injection that's very helpful for testing.
A number of different I/O types are supported:
- Process environment (variables, working directy etc), via
Env
- Standard streams (stdin, stdout and stderr), via
StdStreams
- Filesystem access, via
Fs
In addition to "native" implementations for each trait, "simulated" implementations are also built-in:
SimulatedEnv
for faking process environment stateSimulatedStdStreams
for faking standard stream input and inspecting outputTempFs
for performing filesystem access in achroot
-like sandbox isolated from the rest of the filesystem
Each provider trait can be used independently, however there is also the all-encompassing
Io
which provides access to all of them. If you have a variety of I/O
dependencies, it might be easiest to create and pass around a single &mut Io
.
Documentation
Examples
Cargo.toml
:
[]
= "0.2.0-beta.2"
src/main.rs
:
extern crate io_providers;
use Write;
use Path;
use ;
/// Gets the current working directory and prints it to stdout.
License
io-providers
is distributed under the MIT license.