Crates.io | mockpipe |
lib.rs | mockpipe |
version | 0.1.6 |
source | src |
created_at | 2024-10-05 19:21:11.724396 |
updated_at | 2024-10-06 00:00:05.292574 |
description | A lightweight, thread-safe in-memory pipe, perfect for testing and mocking communication interfaces |
homepage | |
repository | https://github.com/dmidem/mockpipe |
max_upload_size | |
id | 1398402 |
size | 55,019 |
An in-memory, thread-safe, bidirectional pipe for Rust applications. It provides functionality for reading and writing data with optional timeout support. MockPipe utilizes an internal in-memory circular buffer without relying on operating system resources and implements Rust's standard Read
and Write
traits. This makes it a useful tool for testing applications that use communication mechanisms like sockets, pipes, or serial ports.
use std::io::{Read, Write};
use mockpipe::MockPipe;
fn main() {
let (mut pipe1, mut pipe2) = MockPipe::pair(1024);
let write_data = b"hello";
pipe1.write_all(write_data).unwrap();
let mut read_data = [0u8; 5];
pipe2.read_exact(&mut read_data).unwrap();
assert_eq!(&read_data, write_data);
}
More examples can be found in the examples folder in the root of this repository.
unsafe
blocks.std::io::Read
and std::io::Write
traits for seamless integration with Rust's I/O ecosystem.Licensed under either of Apache License, Version 2.0 (LICENSE-APACHE) or MIT license (LICENSE-MIT) at your option.