A Rust utility library to test resilience of Read
or Write
wrappers.
If you'd like to help out, see CONTRIBUTING.md.
Documentation (latest release)
```rust use std::io::{self, Cursor, Read};
use partial_io::{PartialOp, PartialRead};
let data = b"Hello, world!".tovec();
let cursor = Cursor::new(data); // Cursor
let mut out = vec![0; 256];
// The first read will read 7 bytes. asserteq!(partialread.read(&mut out).unwrap(), 7); asserteq!(&out[..7], b"Hello, "); // The second read will fail with ErrorKind::Interrupted. asserteq!(partialread.read(&mut out[7..]).unwraperr().kind(), io::ErrorKind::Interrupted); // The iterator has run out of operations, so it no longer truncates reads. asserteq!(partialread.read(&mut out[7..]).unwrap(), 6); assert_eq!(&out[..13], b"Hello, world!"); ```
Add this to your Cargo.toml
:
toml
[dev-dependencies]
partial-io = "0.3"
Next, add this to your crate:
```rust
extern crate partial_io; ```
Now you can use partial-io
in your tests.
partial-io
can optionally integrate with the tokio-io
library to provide
wrappers for AsyncRead
and AsyncWrite
instances. Enable the tokio
feature
to use this:
toml
[dev-dependencies]
partial-io = { version = "0.3", features = ["tokio"] }
partial-io
can optionally integrate with the quickcheck
library to generate
random test cases. Enable the quickcheck
feature to use this:
toml
[dev-dependencies]
partial-io = { version = "0.3", features = ["quickcheck"] }
See the
documentation
for how to use quickcheck
to generate tests.
partial-io
is MIT-licensed.