Struct heapless::spsc::Queue[][src]

pub struct Queue<T, const N: usize> { /* fields omitted */ }
Expand description

A statically allocated single producer single consumer queue with a capacity of N - 1 elements

IMPORTANT: To get better performance use a capacity that is a power of 2 (e.g. 16, 32, etc.).

Implementations

impl<T, const N: usize> Queue<T, N>[src]

pub const fn new() -> Self[src]

Creates an empty queue with a fixed capacity of N - 1

pub const fn capacity(&self) -> usize[src]

Returns the maximum number of elements the queue can hold

pub fn len(&self) -> usize[src]

Returns the number of elements in the queue

pub fn is_empty(&self) -> bool[src]

Returns true if the queue is empty

pub fn is_full(&self) -> bool[src]

Returns true if the queue is full

pub fn iter(&self) -> Iter<'_, T, N>

Notable traits for Iter<'a, T, N>

impl<'a, T, const N: usize> Iterator for Iter<'a, T, N> type Item = &'a T;
[src]

Iterates from the front of the queue to the back

pub fn iter_mut(&mut self) -> IterMut<'_, T, N>

Notable traits for IterMut<'a, T, N>

impl<'a, T, const N: usize> Iterator for IterMut<'a, T, N> type Item = &'a mut T;
[src]

Returns an iterator that allows modifying each value

pub fn enqueue(&mut self, val: T) -> Result<(), T>[src]

Adds an item to the end of the queue

Returns back the item if the queue is full

pub fn dequeue(&mut self) -> Option<T>[src]

Returns the item in the front of the queue, or None if the queue is empty

pub fn peek(&self) -> Option<&T>[src]

Returns a reference to the item in the front of the queue without dequeuing, or None if the queue is empty.

Examples

use heapless::spsc::Queue;

let mut queue: Queue<u8, 235> = Queue::new();
let (mut producer, mut consumer) = queue.split();
assert_eq!(None, consumer.peek());
producer.enqueue(1);
assert_eq!(Some(&1), consumer.peek());
assert_eq!(Some(1), consumer.dequeue());
assert_eq!(None, consumer.peek());

pub unsafe fn enqueue_unchecked(&mut self, val: T)[src]

Adds an item to the end of the queue, without checking if it’s full

Unsafety

If the queue is full this operation will leak a value (T’s destructor won’t run on the value that got overwritten by item), and will allow the dequeue operation to create a copy of item, which could result in T’s destructor running on item twice.

pub unsafe fn dequeue_unchecked(&mut self) -> T[src]

Returns the item in the front of the queue, without checking if there is something in the queue

Unsafety

If the queue is empty this operation will return uninitialized memory.

pub fn split(&mut self) -> (Producer<'_, T, N>, Consumer<'_, T, N>)[src]

Splits a queue into producer and consumer endpoints

Trait Implementations

impl<T, const N: usize> Clone for Queue<T, N> where
    T: Clone
[src]

fn clone(&self) -> Self[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T, const N: usize> Debug for Queue<T, N> where
    T: Debug
[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<T, const N: usize> Drop for Queue<T, N>[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl<T, const N: usize> Hash for Queue<T, N> where
    T: Hash
[src]

fn hash<H: Hasher>(&self, state: &mut H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl<T, const N: usize> Hash for Queue<T, N> where
    T: Hash
[src]

fn hash<H: Hasher>(&self, state: &mut H)[src]

Feeds this value into the given Hasher.

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
[src]

Feeds a slice of this type into the given Hasher.

impl<'a, T, const N: usize> IntoIterator for &'a Queue<T, N>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T, N>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

impl<'a, T, const N: usize> IntoIterator for &'a mut Queue<T, N>[src]

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T, N>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

impl<T, const N: usize, const N2: usize> PartialEq<Queue<T, N2>> for Queue<T, N> where
    T: PartialEq
[src]

fn eq(&self, other: &Queue<T, N2>) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<T, const N: usize> Eq for Queue<T, N> where
    T: Eq
[src]

Auto Trait Implementations

impl<T, const N: usize> Send for Queue<T, N> where
    T: Send

impl<T, const N: usize> !Sync for Queue<T, N>

impl<T, const N: usize> Unpin for Queue<T, N> where
    T: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.