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

    pub struct Queue<T, N, U = usize, C = MultiCore>(_)
     where
        N: ArrayLength<T>,
        U: Uxx,
        C: XCore;

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

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

By default `spsc::Queue` will use `usize` integers to hold the indices to its head and tail. For small queues `usize` indices may be overkill. However, `spsc::Queue`'s index type is generic and can be changed to `u8` or `u16` to reduce its footprint. The easiest to construct a `spsc::Queue` with a smaller index type is to use the `u8` and `u16` constructors.

IMPORTANT: `spsc::Queue<_, _, u8>` has a maximum capacity of 255 elements; `spsc::Queue<_, _, u16>` has a maximum capacity of 65535 elements.

`spsc::Queue` also comes in a single core variant. This variant can be created using the following constructors: `u8_sc`, `u16_sc`, `usize_sc` and `new_sc`. This variant is `unsafe` to create because the programmer must make sure that the queue's consumer and producer endpoints (if split) are kept on a single core for their entire lifetime.

## Implementations

### `impl<T, N, U, C> Queue<T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore,` [src]

#### `pub fn split<'rb>(
&'rb mut self
) -> (Producer<'rb, T, N, U, C>, Consumer<'rb, T, N, U, C>)` [src]

Splits a statically allocated queue into producer and consumer end points

### `impl<T, N, U, C> Queue<T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore,` [src]

#### `pub fn capacity(&self) -> U` [src]

Returns the maximum number of elements the queue can hold

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

Returns `true` if the queue has a length of 0

#### `pub fn iter(&self) -> Iter<'_, T, N, U, C>ⓘ

### Notable traits for Iter<'a, T, N, U, C>

`impl<'a, T, N, U, C> Iterator for Iter<'a, T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore, type Item = &'a T;`
` [src]

Iterates from the front of the queue to the back

#### `pub fn iter_mut(&mut self) -> IterMut<'_, T, N, U, C>ⓘ

### Notable traits for IterMut<'a, T, N, U, C>

`impl<'a, T, N, U, C> Iterator for IterMut<'a, T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore, type Item = &'a mut T;`
` [src]

Returns an iterator that allows modifying each value.

### `impl<T, N> Queue<T, N, usize, MultiCore> where
N: ArrayLength<T>,` [src]

#### `pub fn new() -> Self` [src]

Alias for `spsc::Queue::usize`

### `impl<T, N> Queue<T, N, usize, SingleCore> where
N: ArrayLength<T>,` [src]

#### `pub unsafe fn new_sc() -> Self` [src]

Alias for `spsc::Queue::usize_sc`

### `impl<T, N> Queue<T, N, u8, MultiCore> where
N: ArrayLength<T>,` [src]

#### `pub fn u8() -> Self` [src]

Creates an empty queue with a fixed capacity of `N`

### `impl<T, N> Queue<T, N, u8, SingleCore> where
N: ArrayLength<T>,` [src]

#### `pub unsafe fn u8_sc() -> Self` [src]

Creates an empty queue with a fixed capacity of `N` (single core variant)

### `impl<T, N, C> Queue<T, N, u8, C> where
N: ArrayLength<T>,
C: XCore,` [src]

#### `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;
    use heapless::consts::*;

    let mut queue: Queue<u8, U235, _> = Queue::u8();
    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 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 enqueue(&mut self, item: T) -> Result<(), T>` [src]

Adds an `item` to the end of the queue

Returns back the `item` if the queue is full

#### `pub unsafe fn enqueue_unchecked(&mut self, item: 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 fn len(&self) -> u8` [src]

Returns the number of elements in the queue

### `impl<T, N> Queue<T, N, u16, MultiCore> where
N: ArrayLength<T>,` [src]

#### `pub fn u16() -> Self` [src]

Creates an empty queue with a fixed capacity of `N`

### `impl<T, N> Queue<T, N, u16, SingleCore> where
N: ArrayLength<T>,` [src]

#### `pub unsafe fn u16_sc() -> Self` [src]

Creates an empty queue with a fixed capacity of `N` (single core variant)

### `impl<T, N, C> Queue<T, N, u16, C> where
N: ArrayLength<T>,
C: XCore,` [src]

#### `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;
    use heapless::consts::*;

    let mut queue: Queue<u8, U235, _> = Queue::u8();
    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 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 enqueue(&mut self, item: T) -> Result<(), T>` [src]

Adds an `item` to the end of the queue

Returns back the `item` if the queue is full

#### `pub unsafe fn enqueue_unchecked(&mut self, item: 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 fn len(&self) -> u16` [src]

Returns the number of elements in the queue

### `impl<T, N> Queue<T, N, usize, MultiCore> where
N: ArrayLength<T>,` [src]

#### `pub fn usize() -> Self` [src]

Creates an empty queue with a fixed capacity of `N`

### `impl<T, N> Queue<T, N, usize, SingleCore> where
N: ArrayLength<T>,` [src]

#### `pub unsafe fn usize_sc() -> Self` [src]

Creates an empty queue with a fixed capacity of `N` (single core variant)

### `impl<T, N, C> Queue<T, N, usize, C> where
N: ArrayLength<T>,
C: XCore,` [src]

#### `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;
    use heapless::consts::*;

    let mut queue: Queue<u8, U235, _> = Queue::u8();
    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 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 enqueue(&mut self, item: T) -> Result<(), T>` [src]

Adds an `item` to the end of the queue

Returns back the `item` if the queue is full

#### `pub unsafe fn enqueue_unchecked(&mut self, item: 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 fn len(&self) -> usize` [src]

Returns the number of elements in the queue

## Trait Implementations

### `impl<T, N, C> Clone for Queue<T, N, u8, C> where
T: Clone,
N: ArrayLength<T>,
C: XCore,` [src]

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

Returns a copy of the value. Read more

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

Performs copy-assignment from `source`. Read more

### `impl<T, N, C> Clone for Queue<T, N, u16, C> where
T: Clone,
N: ArrayLength<T>,
C: XCore,` [src]

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

Returns a copy of the value. Read more

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

Performs copy-assignment from `source`. Read more

### `impl<T, N, C> Clone for Queue<T, N, usize, C> where
T: Clone,
N: ArrayLength<T>,
C: XCore,` [src]

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

Returns a copy of the value. Read more

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

Performs copy-assignment from `source`. Read more

### `impl<T, N, U, C> Debug for Queue<T, N, U, C> where
N: ArrayLength<T>,
T: Debug,
U: Uxx,
C: XCore,` [src]

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

Formats the value using the given formatter. Read more

### `impl<T, N, U, C> Drop for Queue<T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore,` [src]

#### `fn drop(&mut self)` [src]

Executes the destructor for this type. Read more

### `impl<T, N, U, C> Eq for Queue<T, N, U, C> where
T: Eq,
N: ArrayLength<T>,
U: Uxx,
C: XCore,` [src]

### `impl<T, N, U, C> Hash for Queue<T, N, U, C> where
N: ArrayLength<T>,
T: Hash,
U: Uxx,
C: XCore,` [src]

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

Feeds this value into the given `Hasher`. Read more

#### `pub 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, N, U, C> Hash for Queue<T, N, U, C> where
N: ArrayLength<T>,
T: Hash,
U: Uxx,
C: XCore,` [src]

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

Feeds this value into the given `Hasher`.

#### `pub 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, N, U, C> IntoIterator for &'a Queue<T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore,` [src]

#### `type Item = &'a T`

The type of the elements being iterated over.

#### `type IntoIter = Iter<'a, T, N, U, C>`

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, N, U, C> IntoIterator for &'a mut Queue<T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore,` [src]

#### `type Item = &'a mut T`

The type of the elements being iterated over.

#### `type IntoIter = IterMut<'a, T, N, U, C>`

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, N, U, C, N2, U2, C2> PartialEq<Queue<T, N2, U2, C2>> for Queue<T, N, U, C> where
T: PartialEq,
N: ArrayLength<T>,
U: Uxx,
C: XCore,
N2: ArrayLength<T>,
U2: Uxx,
C2: XCore,` [src]

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

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

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

This method tests for `!=`.

## Auto Trait Implementations

### `impl<T, N, U, C> Send for Queue<T, N, U, C> where
C: Send,
T: Send,` [src]

### `impl<T, N, U = usize, C = MultiCore> !Sync for Queue<T, N, U, C>` [src]

### `impl<T, N, U, C> Unpin for Queue<T, N, U, C> where
C: Unpin,
U: Unpin,
<N as ArrayLength<T>>::ArrayType: Unpin,` [src]

## 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> Same<T> for T` [src]

#### `type Output = T`

Should always be `Self`

### `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.