Skip to content

A lightweight, thread-safe in-memory pipe, perfect for testing and mocking communication interfaces.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

dmidem/mockpipe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MockPipe

Crates.io Docs.rs Actions MSRV Release License

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.

Documentation

Example

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.

Features

  • Loopback mode: Create a pipe that writes data into a buffer and allows reading the same data back from the same buffer, simulating a loopback interface.
  • Paired pipes: Create two pipe instances that can exchange data in a full-duplex manner, simulating a communication channel between two endpoints.
  • Timeout support: Specify a timeout for reading and writing operations to test different behaviors in blocking and non-blocking scenarios.
  • No OS resource usage & No unsafe code: Operates without relying on operating system resources and is implemented entirely with safe Rust, without any unsafe blocks.
  • In-memory operation: Does not consume OS-level resources, ideal for unit testing.
  • Standard IO trait support: Implements std::io::Read and std::io::Write traits for seamless integration with Rust's I/O ecosystem.

License

Licensed under either of Apache License, Version 2.0 (LICENSE-APACHE) or MIT license (LICENSE-MIT) at your option.

About

A lightweight, thread-safe in-memory pipe, perfect for testing and mocking communication interfaces.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages