Skip to main content

Queue

Struct Queue 

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

Type-safe FIFO queue with compile-time capacity.

T must be a plain-old-data type (Copy) because items are transferred through the C API via raw byte copies. N is the queue capacity.

Implementations§

Source§

impl<T: Copy, const N: usize> Queue<T, N>

Source

pub fn new() -> Result<Self>

Create a queue via heap allocation (only in heap mode).

Source

pub fn create(storage: &'static QueueStorage<T, N>) -> Result<Self>

Mode-agnostic constructor (see crate::Mutex::create). Heap mode ignores storage; zero-heap mode backs the queue with its storage and embedded item buffer.

Source

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

Send an item, blocking indefinitely if the queue is full. std::sync::mpsc::SyncSender::send analog.

item is taken by &T rather than by value because the substrate memcpys the bytes — T: Copy is enforced at the Queue<T, N> type level, so &T vs T is a wash semantically and &T avoids one stack-side memcpy for large T.

Source

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

Non-blocking send. std::sync::mpsc::SyncSender::try_send analog.

§Errors

Returns Error::QueueFull if the queue is full.

Source

pub fn try_send_for(&self, item: &T, d: Duration) -> Result<()>

Send, waiting up to d.

§Errors

Returns Error::QueueFull / Error::Timeout if the queue stays full through d.

Source

pub fn try_send_until(&self, item: &T, deadline: Instant) -> Result<()>

Send by the given deadline. Use Instant::FOREVER for an indefinite wait.

Source

pub fn recv(&self) -> Result<T>

Receive an item, blocking indefinitely. std::sync::mpsc::Receiver::recv analog.

Source

pub fn try_recv(&self) -> Result<T>

Non-blocking receive. std::sync::mpsc::Receiver::try_recv analog.

§Errors

Returns Error::QueueEmpty if the queue is empty.

Source

pub fn try_recv_for(&self, d: Duration) -> Result<T>

Receive, waiting up to d.

§Errors

Returns Error::QueueEmpty / Error::Timeout if no item is available within d.

Source

pub fn try_recv_until(&self, deadline: Instant) -> Result<T>

Receive by the given deadline.

Source

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

Send an item from an ISR context (non-blocking, returns immediately if full).

§Errors

Returns Error::QueueFull if the queue has no space.

Source

pub fn receive_from_isr(&self) -> Result<T>

Receive an item from an ISR context (non-blocking, returns immediately if empty).

§Errors

Returns Error::QueueEmpty if the queue is empty.

Source

pub unsafe fn set_notify( &self, cb: Option<unsafe extern "C" fn(*mut c_void)>, user_data: *mut c_void, ) -> Result<()>

Register a notify callback fired after every successful send. Wraps the C-level ove_queue_set_notify. Reach for AsyncQueue instead of using this directly — it hides the lifetime + ISR-safety constraints behind a safe API.

§Safety

Same contract as crate::Stream::set_notify: user_data must outlive the registration, and cb must be ISR-safe.

Trait Implementations§

Source§

impl<T: Copy, const N: usize> Debug for Queue<T, N>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Copy, const N: usize> Drop for Queue<T, N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

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

Source§

impl<T: Copy + Send, const N: usize> Sync for Queue<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for Queue<T, N>

§

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

§

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

§

impl<T, const N: usize> UnsafeUnpin for Queue<T, N>

§

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