rbuf/lib.rs
1// Copyright (C) 2020-2025 Daniel Mueller <deso@posteo.net>
2// SPDX-License-Identifier: (Apache-2.0 OR MIT)
3
4//! A library providing a general purpose ring buffer implementation
5//! with some non-standard constraints.
6
7mod iter;
8mod ring;
9
10pub use iter::RingIter;
11pub use iter::RingIterMut;
12pub use ring::RingBuf;
13
14
15/// Create a [`RingBuf`] containing the provided elements.
16///
17/// This macro provides a concise way for creating a `RingBuf` object
18/// from a `Vec`, wrapping the [`RingBuf::from_vec`] constructor. Please
19/// refer to it for precise semantics.
20///
21/// # Examples
22/// ```rust
23/// # use rbuf::ring_buf;
24/// let mut buf = ring_buf![1, 2, 3, 4];
25/// assert_eq!(*buf.front(), 1);
26/// assert_eq!(*buf.back(), 4);
27/// ```
28#[macro_export]
29macro_rules! ring_buf [
30 ($($x:expr), *) => {
31 ::rbuf::RingBuf::from_vec(::std::vec![$($x),*])
32 };
33 ($($x:expr,) *) => {
34 ::rbuf::RingBuf::from_vec(::std::vec![$($x),*])
35 };
36];