Expand description
Promisqs (pronounced “promiscuous”) cross-platform, shared memory, multi-producer, multi-consumer queue implementation.
The main use-case for this library is for ultra low latency inter-process communication (IPC), significantly faster than you would get using any other means, like sockets, UNIX sockets (named pipes on windows) and even things like DBUS on Linux. For smaller sized types (a few kB or smaller), Promisqs can easily achieve a latency of a few tenths of a micro-second!
The queue implementation ShmemQueue is generic, allowing most primitive types, and any type that implements the FromBytes,
IntoBytes, and Immutable traits, to be used with the queue.
Note that these traits cannot be implemented directly for a type, and must be directly derived, due to safety concerns. Most primitive types and other fixed size types, like enums, arrays etc. can be used with the queue. Dynamic types like strings or vectors cannot.
NOTE - In order to implement these traits for your type, you must add zerocopy as a dependency to your crate.
§Producer Example
use promisqs::{ShmemQueue, IntoBytes, FromBytes, Immutable};
// Define a struct that derives `zerocopy` traits,
// so that we can use it with promisqs queues
#[derive(Debug, Clone, IntoBytes, FromBytes, Immutable, PartialEq)]
pub struct Message {
id: u8,
address: [u8; 4],
payload: [u8; 4],
}
let mut q = ShmemQueue::<Message>::create("flink.map", 1).unwrap();
let msg = Message {
id: 0x0,
address: [0xc8, 0xa8, 0x1, 0x1],
payload: [01, 0x2, 0x3, 0x4],
};
q.push(&msg).unwrap();
§Consumer Example (different process)
use promisqs::{ShmemQueue, IntoBytes, FromBytes, Immutable};
#[derive(Debug, Clone, IntoBytes, FromBytes, Immutable, PartialEq)]
pub struct Message {
id: u8,
address: [u8; 4],
payload: [u8; 4],
}
let mut q = ShmemQueue::<Message>::open("flink.map").unwrap();
let expected_msg = Message {
id: 0x0,
address: [0xc8, 0xa8, 0x1, 0x1],
payload: [01, 0x2, 0x3, 0x4],
};
assert_eq!(q.pop().unwrap(), expected_msg);
Re-exports§
pub use error::PromisqsError;pub use queue::PromisqsResult;pub use queue::ShmemQueue;
Modules§
Traits§
- From
Bytes - Types for which any bit pattern is valid.
- Immutable
- Types which are free from interior mutability.
- Into
Bytes - Types that can be converted to an immutable slice of initialized bytes.