Struct multi_stack_queue::MultiStackQueue[][src]

pub struct MultiStackQueue<T, const N: usize, const M: usize> { /* fields omitted */ }
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

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

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.