Struct multi_stack_queue::MultiStackQueue [−][src]
Expand description
An abstract structure containin multiple stack-allocated bounded queues.
Each queue is stored as an [Option<T>; N]
and the multiqueue stores
Usage
The generic definition is the following :
ⓘ
MultiStackQueue<T, const N: usize, const M: usize>
With :
T
- type contained in the queuesN
- length of each queueM
- number of queues
Example usecases
- When writing a simple micro-kernel, the scheduler may need some sort of multiple Round-Robins. Having it allocated on the stack removes the need for a heap allocator, which can be useful when working on this kind of ressource-limited target.
Examples
use multi_stack_queue::MultiStackQueue; #[derive(Clone, Copy, Debug, PartialEq, Eq)] struct TestStruct { a: usize, b: bool, } let mut msq: MultiStackQueue<TestStruct, 16, 8> = MultiStackQueue::new(); let value = TestStruct { a: 42, b: false }; msq.push(7, value).unwrap(); assert_eq!(msq.pop(7).unwrap(), value);
Implementations
Returns a new empty multiqueue.
Examples
use multi_stack_queue::MultiStackQueue; // Returns a fresh empty multiqueue containing 8 queues of `usize` with size 16 let a: MultiStackQueue<usize, 16, 8> = MultiStackQueue::new(); #[derive(Clone, Copy)] struct TestStruct { a: usize, b: bool } let random_data = TestStruct { a: 42, b: false }; let msq: MultiStackQueue<TestStruct, 4, 2> = MultiStackQueue::new();
Appends a value to the multiqueue.
Examples
use multi_stack_queue::MultiStackQueue; #[derive(Clone, Copy)] struct TestStruct { a: usize, b: bool } let random_data = TestStruct { a: 42, b: false }; let mut msq: MultiStackQueue<TestStruct, 4, 2> = MultiStackQueue::new(); msq.push(0, random_data).unwrap();
Pops a value from the multiqueue.
Examples
use multi_stack_queue::MultiStackQueue; #[derive(Clone, Copy)] struct TestStruct { a: usize, b: bool } let random_data = TestStruct { a: 42, b: false }; let mut msq: MultiStackQueue<TestStruct, 4, 2> = MultiStackQueue::new(); msq.push(0, random_data).unwrap(); msq.pop(0).unwrap();
Returns whether a particular queue is full
Examples
use multi_stack_queue::MultiStackQueue; let mut msq: MultiStackQueue<usize, 4, 2> = MultiStackQueue::new(); assert!(!msq.is_full(0)); for _ in 0..4 { msq.push(0, 0); } assert!(msq.is_full(0));
Auto Trait Implementations
impl<T, const N: usize, const M: usize> RefUnwindSafe for MultiStackQueue<T, N, M> where
T: RefUnwindSafe,
impl<T, const N: usize, const M: usize> Send for MultiStackQueue<T, N, M> where
T: Send,
impl<T, const N: usize, const M: usize> Sync for MultiStackQueue<T, N, M> where
T: Sync,
impl<T, const N: usize, const M: usize> Unpin for MultiStackQueue<T, N, M> where
T: Unpin,
impl<T, const N: usize, const M: usize> UnwindSafe for MultiStackQueue<T, N, M> where
T: UnwindSafe,