#data-structures #no-std

no-std const_queue

A stack-only, no_std queue using const generics

2 releases

0.1.1 Jun 17, 2021
0.1.0 May 17, 2021

#98 in #data-structures

Download history 6/week @ 2021-10-10 4/week @ 2021-10-17 8/week @ 2021-10-24 4/week @ 2021-10-31 18/week @ 2021-11-07 22/week @ 2021-11-14 23/week @ 2021-11-21 18/week @ 2021-11-28 14/week @ 2021-12-05 18/week @ 2021-12-12 20/week @ 2021-12-19 24/week @ 2021-12-26 24/week @ 2022-01-02 26/week @ 2022-01-09 15/week @ 2022-01-16

89 downloads per month

0BSD license

7KB
195 lines

Const_Queue

Const_Queue is an implementation of a queue backed by an array, that is suitable for environments where no standard library exists (only libcore).

Implementation Details

Const_Queue implements a ringbuffer to store its items. The implementation will always leave one free slot between the last and the first item of the buffer. This means, that ´ConstQueue<T,4>´ will effectively only hold 3 items.

Example

    let mut q = ConstQueue::<i32, 3>::new();
    let _ = q.push(10);
    let _ = q.push(20);
    assert!(q.pop().unwrap() == 10);
    assert!(q.pop().unwrap() == 20);

We also support iterators:

    let mut q = ConstQueue::<i32, 4>::new();
    let _ = q.push(10);
    let _ = q.push(20);
    let mut values = Vec::<i32>::new();
    for i in q.into_iter()
    {
        values.push(i);
    }

    assert!(values == vec![10,20]);

No runtime deps