Reader Writer Builder
Introduction
This crate provides a convenient way to build std::io::Readers and std::io::Writers by chaining transformations. Since readers and writers are defined simultaneously through the same builder they can be used as inverses of each other.
Usage
Add this to your Cargo.toml:
[]
= "0.0.1"
Warning
This crate is provided "as is" without warranty of any kind. Furthermore, this crate is still in its infancy and lacks significant real world exposure. We try our best to ensure the quality of this crate, but we should warn you that it's more a proof of concept than something to be used in production at the moment.
Example
Let's say you have some application state you want to encrypt and store on disk. Once the application starts up you want to read that state back into memory. A good practice when encrypting is to compress the data beforehand so you may feel the desire to chain some readers and writers together.
use Result;
use Compression;
use ;
use ;
The builder ensures the order of the readers will match the order of the writers so there's no opportunity for mistakes.
Writing something similar in the usual way is much more verbose and error prone.
use Result;
use ;
use ;
use ;
This second example doesn't support streaming, which is necessary in the case of large files. Notice how the save and load functionality is described in reverse order from each other and that configuration options like the file location and the encryption key need to be made available in multiple locations. This is needlessly challenging to maintain when compared to the former example.
Sources and Sinks
You may have noticed that the FileBuilder struct and the bincode function have a special role. They are examples of a source and a sink respectively. Sources are a typical starting point for chaining builders, since they can be constructed without an inner builder. Sinks are a typical ending point for chaining builders, since they can interface with other types than &[u8] which Read and Write are restricted to.
Features
To provide the functionality of many different readers and writers this crate has many optional dependencies which are enabled through a predefined set of features. The example above requires the bincode, chacha20 and flate2 features. Currently, the following features are available:
bincode: includes theserdeandbincodecrates and enables theSerDetrait and thebincodefunction on theRwBuildertrait.chacha20: includes thecipherandchacha20crates and enables thechacha20function on theRwBuildertrait.salsa20: includes thecipherandsalsa20crates and enables thesalsa20function on theRwBuildertrait.flate2: includes theflate2crate and enables thecrc,deflate,gzandzlibfunctions on theRwBuildertrait.
Contributing
See CONTRIBUTING.md.
License
The rw-builder crate is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.
See LICENSE-APACHE.txt, LICENSE-MIT.txt, and COPYRIGHT.txt for details.