https://github.com/devashishdxt/mock-io
Mock IO listener and stream for Rust
https://github.com/devashishdxt/mock-io
Last synced: 7 months ago
JSON representation
Mock IO listener and stream for Rust
- Host: GitHub
- URL: https://github.com/devashishdxt/mock-io
- Owner: devashishdxt
- License: other
- Created: 2020-10-19T14:35:55.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-08-09T10:13:01.000Z (over 2 years ago)
- Last Synced: 2025-08-03T11:16:52.603Z (8 months ago)
- Language: Rust
- Size: 41 KB
- Stars: 7
- Watchers: 1
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# mock-io
[](https://github.com/devashishdxt/mock-io/actions?query=workflow%3ACI)
[](https://crates.io/crates/mock-io)
[](https://docs.rs/mock-io)
[](https://github.com/devashishdxt/mock-io/blob/main/LICENSE-MIT)
A crate with mock IO stream and listener implementations.
## Usage
Add `mock-io` in your `Cargo.toml`'s `dependencies` section:
```toml
[dependencies]
mock-io = "0.3"
```
Here is a sample usage of this crate:
```rust
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 (using `futures::io::{AsyncRead, AsyncWrite}`)
- **Disabled** by default
- `async-tokio`: Enables async mock IO stream and listener (using `tokio::io::{AsyncRead, AsyncWrite}`)
- **Disabled** by default
> Note: Some functions in this crate returns a `Future`. So, you'll need an executor to drive `Future`s returned
from these functions. `async-std` and `tokio` are two popular options.
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))
at your option.
## Contribution
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.