#partial #tokio #quickcheck #interrupted #wouldblock

dev partial-io

Helpers to test partial, interrupted and would-block I/O operations

9 releases

✓ Uses Rust 2018 edition

0.3.1 Jun 7, 2019
0.3.0 Jan 12, 2018
0.2.5 Nov 18, 2017
0.2.4 Aug 19, 2017
0.1.1 May 27, 2017

#31 in Testing

Download history 3450/week @ 2019-11-01 3980/week @ 2019-11-08 4597/week @ 2019-11-15 4974/week @ 2019-11-22 4372/week @ 2019-11-29 4696/week @ 2019-12-06 4814/week @ 2019-12-13 2396/week @ 2019-12-20 1483/week @ 2019-12-27 3253/week @ 2020-01-03 3986/week @ 2020-01-10 3605/week @ 2020-01-17 4614/week @ 2020-01-24 2603/week @ 2020-01-31 1632/week @ 2020-02-07

15,691 downloads per month
Used in 7 crates

MIT license

33KB
548 lines

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

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

use partial_io::{PartialOp, PartialRead};

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

let mut out = vec![0; 256];

// The first read will read 7 bytes.
assert_eq!(partial_read.read(&mut out).unwrap(), 7);
assert_eq!(&out[..7], b"Hello, ");
// The second read will fail with ErrorKind::Interrupted.
assert_eq!(partial_read.read(&mut out[7..]).unwrap_err().kind(), io::ErrorKind::Interrupted);
// The iterator has run out of operations, so it no longer truncates reads.
assert_eq!(partial_read.read(&mut out[7..]).unwrap(), 6);
assert_eq!(&out[..13], b"Hello, world!");

Quick start

Add this to your Cargo.toml:

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

Next, add this to your crate:

#[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:

[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:

[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.

Dependencies

~185KB