swap_buffer_queue/
lib.rs

1#![forbid(clippy::dbg_macro)]
2#![forbid(clippy::semicolon_if_nothing_returned)]
3#![forbid(missing_docs)]
4#![forbid(unsafe_op_in_unsafe_fn)]
5#![forbid(clippy::undocumented_unsafe_blocks)]
6#![cfg_attr(docsrs, feature(doc_auto_cfg))]
7#![cfg_attr(not(feature = "std"), no_std)]
8//! # swap-buffer-queue
9//! A buffering MPSC queue.
10//!
11//! This library is intended to be a (better, I hope) alternative to traditional MPSC queues
12//! in the context of a buffering consumer, by moving the buffering part directly into the queue.
13//!
14//! It is especially well suited for IO writing workflow, see [`mod@write`] and [`write_vectored`].
15//!
16//! The crate is *no_std* (some buffer implementations may require `std`).
17//!
18//! In addition to the low level `Queue` implementation, a higher level `SynchronizedQueue` is
19//! provided with both blocking and asynchronous methods.
20//!
21//! # Examples
22//!
23//! ```rust
24//! # use std::ops::Deref;
25//! # use swap_buffer_queue::{buffer::{IntoValueIter, VecBuffer}, Queue};
26//! // Initialize the queue with a capacity
27//! let queue: Queue<VecBuffer<usize>> = Queue::with_capacity(42);
28//! // Enqueue some value
29//! queue.try_enqueue([0]).unwrap();
30//! // Multiple values can be enqueued at the same time
31//! // (optimized compared to multiple enqueuing)
32//! queue.try_enqueue([1, 2]).unwrap();
33//! let mut values = vec![3, 4];
34//! queue
35//!     .try_enqueue(values.drain(..).into_value_iter())
36//!     .unwrap();
37//! // Dequeue a slice to the enqueued values
38//! let slice = queue.try_dequeue().unwrap();
39//! assert_eq!(slice.deref(), &[0, 1, 2, 3, 4]);
40//! // Enqueued values can also be retrieved
41//! assert_eq!(slice.into_iter().collect::<Vec<_>>(), vec![0, 1, 2, 3, 4]);
42//! ```
43
44#[cfg(feature = "alloc")]
45extern crate alloc;
46
47pub mod buffer;
48pub mod error;
49mod loom;
50pub mod notify;
51mod queue;
52#[cfg(feature = "std")]
53mod synchronized;
54mod utils;
55#[cfg(feature = "write")]
56pub mod write;
57#[cfg(feature = "write")]
58#[cfg(feature = "std")]
59pub mod write_vectored;
60
61pub use queue::Queue;
62#[cfg(feature = "std")]
63pub use synchronized::{SynchronizedNotifier, SynchronizedQueue};