Crates.io | const_queue |
lib.rs | const_queue |
version | |
source | src |
created_at | 2021-05-17 17:54:07.02679 |
updated_at | 2021-06-17 19:52:57.979328 |
description | A stack-only, no_std queue using const generics |
homepage | https://github.com/rincewound/const_queue |
repository | https://github.com/rincewound/const_queue |
max_upload_size | |
id | 398680 |
size | 0 |
Const_Queue is an implementation of a queue backed by an array, that is suitable for environments where no standard library exists (only libcore).
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.
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]);