1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! 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 std::{thread, io::{Read, Write}};
//! 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.