QueueInner

Struct QueueInner 

Source
pub struct QueueInner<T, S: Storage> { /* private fields */ }
Expand description

Base struct for Queue and QueueView, generic over the Storage.

In most cases you should use Queue or QueueView directly. Only use this struct if you want to write code that’s generic over both.

Implementations§

Source§

impl<T, const N: usize> QueueInner<T, OwnedStorage<N>>

Source

pub const fn new() -> Self

👎Deprecated: See the documentation of Queue::new() for more information: https://docs.rs/heapless/latest/heapless/mpmc/type.Queue.html#method.new

Creates an empty queue.

§Deprecation
The current implementation of `mpmc` is marked as deprecated due to not being truly lock-free

If a thread is parked, or pre-empted for a long time by an higher-priority task during an enqueue or dequeue operation, it is possible that the queue ends-up in a state were no other task can successfully enqueue or dequeue items from it until the pre-empted task can finish its operation.

In that case, enqueue and dequeue will return an error, but will not panic or reach undefined behaviour

This makes mpmc unsuitable for some use cases such as using it as a pool of objects.

§When can this queue be used?

This queue should be used for cross-task communication only when items sent over the queue can be dropped in case of concurrent operations, or when it is possible to retry the dequeue/enqueue operation after other tasks have had the opportunity to make progress.

In that case you can safely ignore the warnings using #[expect(deprecated)] when new is called

For more information, and possible alternative, please see https://github.com/rust-embedded/heapless/issues/583

Source§

impl<T, S: Storage> QueueInner<T, S>

Source

pub fn capacity(&self) -> usize

Returns the maximum number of elements the queue can hold.

Source

pub fn as_view(&self) -> &QueueView<T>

Get a reference to the Queue, erasing the N const-generic.

let queue: Queue<u8, 2> = Queue::new();
let view: &QueueView<u8> = queue.as_view();

It is often preferable to do the same through type coerction, since Queue<T, N> implements Unsize<QueueView<T>>:

let queue: Queue<u8, 2> = Queue::new();
let view: &QueueView<u8> = &queue;
Source

pub fn as_mut_view(&mut self) -> &mut QueueView<T>

Get a mutable reference to the Queue, erasing the N const-generic.

#[expect(deprecated)]
let mut queue: Queue<u8, 2> = Queue::new();
let view: &mut QueueView<u8> = queue.as_mut_view();

It is often preferable to do the same through type coerction, since Queue<T, N> implements Unsize<QueueView<T>>:

#[expect(deprecated)]
let mut queue: Queue<u8, 2> = Queue::new();
let view: &mut QueueView<u8> = &mut queue;
Source

pub fn dequeue(&self) -> Option<T>

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

Source

pub fn enqueue(&self, item: T) -> Result<(), T>

Adds an item to the end of the queue.

Returns back the item if the queue is full.

Trait Implementations§

Source§

impl<T, S: Storage> Drop for QueueInner<T, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, S: Storage> Sync for QueueInner<T, S>
where T: Send,

Auto Trait Implementations§

§

impl<T, S> !Freeze for QueueInner<T, S>

§

impl<T, S> !RefUnwindSafe for QueueInner<T, S>

§

impl<T, S> Send for QueueInner<T, S>
where <S as SealedStorage>::Buffer<Cell<T>>: Send,

§

impl<T, S> Unpin for QueueInner<T, S>
where <S as SealedStorage>::Buffer<Cell<T>>: Unpin,

§

impl<T, S> UnwindSafe for QueueInner<T, S>
where <S as SealedStorage>::Buffer<Cell<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.