Mpmc

Struct Mpmc 

Source
pub struct Mpmc<T, const N: usize>(/* private fields */);
Expand description

Multi-producer, multi-consumer, fixed-capacity async queue.

This wraps a MpMcQueue from the heapless crate, adding support for asynchronous enqueue and dequeue operations. N must be a power of two.

Implementations§

Source§

impl<T, const N: usize> Mpmc<T, N>

Source

pub const fn new() -> Self

Creates an empty queue.

Source

pub fn inner(&self) -> &MpMcQueue<T, N>

Accesses the inner MpMcQueue.

Source

pub async fn enqueue<S: EventMask>( &self, item: T, signals: &Signals<'_, S>, ev: S, )

Adds an item to the queue.

If the queue is full, this will wait on ev until a successful insertion. After inserting the item, ev will be raised in order to signal producers.

Source

pub fn try_enqueue<S: EventMask>( &self, item: T, signals: &Signals<'_, S>, ev: S, ) -> Result<(), T>

Attempts to add an item to the queue.

If the queue is currently full, the item is returned in the Err variant. See also Mpmc::enqueue().

Source

pub async fn dequeue<S: EventMask>(&self, signals: &Signals<'_, S>, ev: S) -> T

Removes an item from the queue.

If the queue is empty, this will wait on ev until an item is enqueued. After removing an item, ev will be raised to notify producers of available space in the queue.

Source

pub fn try_dequeue<S: EventMask>( &self, signals: &Signals<'_, S>, ev: S, ) -> Result<T, Infallible>

Attempts to remove an item from the queue.

This will return WouldBlock if the queue is empty. See also Mpmc::dequeue().

Trait Implementations§

Source§

impl<T, const N: usize> Default for Mpmc<T, N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, const N: usize> From<MpMcQueue<T, N>> for Mpmc<T, N>

Source§

fn from(queue: MpMcQueue<T, N>) -> Self

Converts to this type from the input type.
Source§

impl<T, const N: usize> From<Mpmc<T, N>> for MpMcQueue<T, N>

Source§

fn from(queue: Mpmc<T, N>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T, const N: usize> !Freeze for Mpmc<T, N>

§

impl<T, const N: usize> !RefUnwindSafe for Mpmc<T, N>

§

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

§

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

§

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

§

impl<T, const N: usize> UnwindSafe for Mpmc<T, N>
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.