io-providers
Defines "provider" traits and implementations for different types of I/O operations.
The purpose of this is mainly for dependency injection: by having your code depend on a generic provider, it can be tested by giving it a virtual, inspectable implementation of that provider. In production, the "real" implementation can be used.
Each type of provider exists in its own submodule and can be used independently. However,
this module also contains the all-encompassing IoProvider
trait which provides access to
all of them. If you have a lot of I/O dependencies, it might be easier to create and pass
around one &mut IoProvider
rather than several different providers.
Example
extern crate io_providers;
use Write;
use Path;
use ;
use Provider as EnvProvider;
use Provider as StreamProvider;
/// Gets the current working directory and prints it to stdout.
Installing
io-providers
is hosted on crates.io, so to use it simply add it to the [dependencies]
section of your Cargo.toml
:
[dependencies]
io-providers = "0.1"
Usage
Consult the API documentation.
License
io-providers
is distributed under the MIT license.