Struct MultiStackQueue

Source
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 queues
  • N - length of each queue
  • M - 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>

Source

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

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

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

pub fn is_full(&self, id: usize) -> bool

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

pub fn is_empty(&self, id: usize) -> bool

Returns whether a particular queue is empty

§Examples
use multi_stack_queue::MultiStackQueue;

let mut msq: MultiStackQueue<usize, 4, 2> = MultiStackQueue::new();

assert!(msq.is_empty(0));
msq.push(0, 0);
assert!(!msq.is_empty(0));

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.