partial-io Build Status crates.io

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)

Documentation (master)

Example

```rust use std::io::{self, Cursor, Read};

use partial_io::{PartialOp, PartialRead};

let data = b"Hello, world!".tovec(); let cursor = Cursor::new(data); // Cursor> implements io::Read let ops = vec![PartialOp::Limited(7), PartialOp::Err(io::ErrorKind::Interrupted)]; let mut partialread = PartialRead::new(cursor, ops);

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!"); ```

Quick start

Add this to your Cargo.toml:

toml [dev-dependencies] partial-io = "0.3"

Next, add this to your crate:

```rust

[cfg(test)]

extern crate partial_io; ```

Now you can use partial-io in your tests.

Tokio integration

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"] }

QuickCheck integration

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.

License

partial-io is MIT-licensed.