[−][src]Crate mock_io
A crate with mock IO stream and listener implementations.
Usage
Add mock-io
in your Cargo.toml
's dependencies
section:
[dependencies]
mock-io = "0.3"
Here is a sample usage of this crate:
use mock_io::sync::{MockListener, MockStream}; let (listener, handle) = MockListener::new(); thread::spawn(move || { let mut stream = MockStream::connect(&handle).unwrap(); stream.write(&1u64.to_be_bytes()).unwrap(); stream.write(&2u64.to_be_bytes()).unwrap(); }); while let Ok(mut stream) = listener.accept() { let mut buf = [0; 8]; stream.read(&mut buf).unwrap(); assert_eq!(1u64.to_be_bytes(), buf); stream.read(&mut buf).unwrap(); assert_eq!(2u64.to_be_bytes(), buf); }
Features
sync
: Enables sync mock IO stream and listener- Enabled by default
async-futures
: Enables async mock IO stream and listener (usingfutures::io::{AsyncRead, AsyncWrite}
)- Disabled by default
async-tokio
: Enables async mock IO stream and listener (usingtokio::io::{AsyncRead, AsyncWrite}
)- Disabled by default
Note: Some functions in this crate returns a
Future
. So, you'll need an executor to driveFuture
s returned from these functions.async-std
andtokio
are two popular options.
Modules
error | Error types used in this crate |
futures | async-futures Mock IO stream and listener in async context |
sync | sync Mock IO stream and listener in sync context |
tokio | async-tokio Mock IO stream and listener in tokio context |