Skip to main content

persistent_queue/
lib.rs

1//! A durable, at-least-once MPSC queue backed by in-memory and durable backends.
2//!
3//! Items are written to a [`Store`] and survive process and machine crashes.
4//! Delivery is at-least-once: an item is removed only once the consumer acks it,
5//! so a crash between handling and ack redelivers it. The core is synchronous and
6//! runtime-agnostic.
7//!
8//! ```
9//! use persistent_queue::{Builder, MemStore};
10//!
11//! let (tx, rx) = Builder::new(MemStore::new()).capacity(1024).open().unwrap();
12//! tx.push(b"job").unwrap();
13//! let item = rx.reserve().unwrap().unwrap();
14//! assert_eq!(&*item, b"job");
15//! item.ack().unwrap();
16//! ```
17//!
18//! For typed messages, [`Builder::open_typed`] wraps the queue with a [`Codec`] that
19//! encodes on push and decodes on reserve (serde and bincode behind the `serde`
20//! feature).
21//!
22//! See `DESIGN.md` for the on-disk layout, crash recovery, and durability model.
23#![warn(missing_docs)]
24
25mod codec;
26mod error;
27mod queue;
28mod store;
29mod sync;
30mod typed;
31
32pub use codec::{Codec, CodecError};
33pub use error::{OpenError, PushError, TryPushError};
34pub use queue::{Builder, Consumer, Durability, Ends, Producer, Reserved};
35pub use store::{KeyValue, MemStore, Op, Store};
36pub use typed::{
37    ReserveError, TypedConsumer, TypedEnds, TypedProducer, TypedPushError, TypedReserved,
38};
39
40#[cfg(feature = "serde")]
41pub use codec::Bincode;
42
43#[cfg(feature = "redb")]
44pub use store::RedbStore;
45#[cfg(feature = "rocksdb")]
46pub use store::RocksStore;
47#[cfg(feature = "sled")]
48pub use store::SledStore;