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>
impl<T: Copy, const N: usize> Queue<T, N>
Sourcepub fn create(storage: &'static QueueStorage<T, N>) -> Result<Self>
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.
Sourcepub fn send(&self, item: &T) -> Result<()>
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.
Sourcepub fn try_send(&self, item: &T) -> Result<()>
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.
Sourcepub fn try_send_for(&self, item: &T, d: Duration) -> Result<()>
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.
Sourcepub fn try_send_until(&self, item: &T, deadline: Instant) -> Result<()>
pub fn try_send_until(&self, item: &T, deadline: Instant) -> Result<()>
Send by the given deadline. Use
Instant::FOREVER for an
indefinite wait.
Sourcepub fn recv(&self) -> Result<T>
pub fn recv(&self) -> Result<T>
Receive an item, blocking indefinitely. std::sync::mpsc::Receiver::recv
analog.
Sourcepub fn try_recv(&self) -> Result<T>
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.
Sourcepub fn try_recv_for(&self, d: Duration) -> Result<T>
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.
Sourcepub fn try_recv_until(&self, deadline: Instant) -> Result<T>
pub fn try_recv_until(&self, deadline: Instant) -> Result<T>
Receive by the given deadline.
Sourcepub fn send_from_isr(&self, item: &T) -> Result<()>
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.
Sourcepub fn receive_from_isr(&self) -> Result<T>
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.
Sourcepub unsafe fn set_notify(
&self,
cb: Option<unsafe extern "C" fn(*mut c_void)>,
user_data: *mut c_void,
) -> Result<()>
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.