6 releases

0.2.2 Sep 1, 2019
0.2.1 Aug 3, 2019
0.2.0 Jul 24, 2017
0.1.2 Jul 21, 2017

#124 in Data structures

Download history 206/week @ 2019-07-22 267/week @ 2019-07-29 177/week @ 2019-08-05 423/week @ 2019-08-12 315/week @ 2019-08-19 272/week @ 2019-08-26 327/week @ 2019-09-02 487/week @ 2019-09-09 617/week @ 2019-09-16 753/week @ 2019-09-23 517/week @ 2019-09-30 516/week @ 2019-10-07 224/week @ 2019-10-14 464/week @ 2019-10-21 218/week @ 2019-10-28

1,063 downloads per month
Used in 4 crates

MIT/Apache

15KB
287 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 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's a built-in iterator that goes from the newest items to the oldest ones.

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

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));

No runtime deps