pub struct MultiStackQueue<T, const N: usize, const M: usize> { /* private fields */ }
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§
Source§impl<T, const N: usize, const M: usize> MultiStackQueue<T, N, M>
impl<T, const N: usize, const M: usize> MultiStackQueue<T, N, M>
Sourcepub fn new() -> Self
pub fn new() -> Self
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();
Sourcepub fn push(&mut self, id: usize, value: T) -> Result<(), MSQError>
pub fn push(&mut self, id: usize, value: T) -> Result<(), MSQError>
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();
Sourcepub fn pop(&mut self, id: usize) -> Result<T, MSQError>
pub fn pop(&mut self, id: usize) -> Result<T, MSQError>
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();
Auto Trait Implementations§
impl<T, const N: usize, const M: usize> Freeze for MultiStackQueue<T, N, M>where
T: Freeze,
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,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more