Crates.io | mock-io |
lib.rs | mock-io |
version | 0.3.2 |
source | src |
created_at | 2020-10-20 04:28:20.246019 |
updated_at | 2021-06-23 02:16:31.521344 |
description | A crate with mock IO stream and listener implementations |
homepage | https://github.com/devashishdxt/mock-io |
repository | https://github.com/devashishdxt/mock-io |
max_upload_size | |
id | 303310 |
size | 30,823 |
A crate with mock IO stream and listener implementations.
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);
}
sync
: Enables sync mock IO stream and listener
async-futures
: Enables async mock IO stream and listener (using futures::io::{AsyncRead, AsyncWrite}
)
async-tokio
: Enables async mock IO stream and listener (using tokio::io::{AsyncRead, AsyncWrite}
)
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.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.