10 releases

Uses old Rust 2015

0.2.6 Jul 27, 2020
0.2.5 Jun 21, 2020
0.2.4 Mar 26, 2020
0.2.3 Jan 9, 2020
0.1.2 Jul 21, 2017

#1381 in Data structures

Download history 2518/week @ 2024-06-09 2790/week @ 2024-06-16 3930/week @ 2024-06-23 3264/week @ 2024-06-30 3891/week @ 2024-07-07 4021/week @ 2024-07-14 3497/week @ 2024-07-21 3715/week @ 2024-07-28 3347/week @ 2024-08-04 4881/week @ 2024-08-11 4376/week @ 2024-08-18 3811/week @ 2024-08-25 3907/week @ 2024-09-01 4498/week @ 2024-09-08 3325/week @ 2024-09-15 3114/week @ 2024-09-22

15,116 downloads per month
Used in 27 crates (16 directly)

MIT/Apache

25KB
512 lines

circular-queue

crates.io Documentation Build Status Build Status

A circular buffer-like queue container. Created with a set capacity. When pushing new items over capacity, old ones get overwritten. Supports iteration in newest to oldest and in oldest to newest order.

License

Licensed under either of

at your option.


lib.rs:

A circular buffer-like queue.

The CircularQueue<T> is created with a set capacity, then items are pushed in. When the queue runs out of capacity, newer items start overwriting the old ones, starting from the oldest.

There are built-in iterators that go from the newest items to the oldest ones and from the oldest items to the newest ones.

Two queues are considered equal if iterating over them with iter() would yield the same sequence of elements.

Enable the serde_support feature for Serde support.

Examples

use circular_queue::CircularQueue;

let mut queue = CircularQueue::with_capacity(3);
queue.push(1);
queue.push(2);
queue.push(3);
queue.push(4);

assert_eq!(queue.len(), 3);

let mut iter = queue.iter();

assert_eq!(iter.next(), Some(&4));
assert_eq!(iter.next(), Some(&3));
assert_eq!(iter.next(), Some(&2));

Dependencies

~0–390KB