Struct heapless::spsc::Queue [−][src]
pub struct Queue<T, N, U = usize, C = MultiCore>(_)
where
N: ArrayLength<T>,
U: Uxx,
C: XCore;
Expand description
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
Iterates from the front of the queue to the back
Alias for spsc::Queue::usize
Alias for spsc::Queue::usize_sc
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());
Returns the item in the front of the queue, or None
if the queue is empty
Adds an item
to the end of the queue
Returns back the item
if the queue is full
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.
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());
Returns the item in the front of the queue, or None
if the queue is empty
Adds an item
to the end of the queue
Returns back the item
if the queue is full
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.
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());
Returns the item in the front of the queue, or None
if the queue is empty
Adds an item
to the end of the queue
Returns back the item
if the queue is full
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.
Trait Implementations
Performs copy-assignment from source
. Read more
Performs copy-assignment from source
. Read more
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,
impl<T, N, U, C> Debug for Queue<T, N, U, C> where
N: ArrayLength<T>,
T: Debug,
U: Uxx,
C: XCore,
impl<T, N, U, C> Hash for Queue<T, N, U, C> where
N: ArrayLength<T>,
T: Hash,
U: Uxx,
C: XCore,
impl<T, N, U, C> Hash for Queue<T, N, U, C> where
N: ArrayLength<T>,
T: Hash,
U: Uxx,
C: XCore,
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,
impl<T, N, U, C> Hash for Queue<T, N, U, C> where
N: ArrayLength<T>,
T: Hash,
U: Uxx,
C: XCore,
impl<'a, T, N, U, C> IntoIterator for &'a Queue<T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore,
impl<'a, T, N, U, C> IntoIterator for &'a Queue<T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore,
impl<'a, T, N, U, C> IntoIterator for &'a mut Queue<T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore,
impl<'a, T, N, U, C> IntoIterator for &'a mut Queue<T, N, U, C> where
N: ArrayLength<T>,
U: Uxx,
C: XCore,
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,
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,
Auto Trait Implementations
impl<T, N, U, C> Send for Queue<T, N, U, C> where
C: Send,
T: Send,
impl<T, N, U, C> Unpin for Queue<T, N, U, C> where
C: Unpin,
U: Unpin,
<N as ArrayLength<T>>::ArrayType: Unpin,
Blanket Implementations
pub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
pub fn from(t: T) -> T
pub fn from(t: T) -> T
Performs the conversion.
pub fn into(self) -> U
pub fn into(self) -> U
Performs the conversion.