Struct SegQueue
pub struct SegQueue<T> { /* private fields */ }
An unbounded multi-producer multi-consumer queue.
This queue is implemented as a linked list of segments, where each segment is a small buffer
that can hold a handful of elements. There is no limit to how many elements can be in the queue
at a time. However, since segments need to be dynamically allocated as elements get pushed,
this queue is somewhat slower than ArrayQueue.
Examples
use crossbeam_queue::SegQueue;
let q = SegQueue::new();
q.push('a');
q.push('b');
assert_eq!(q.pop(), Some('a'));
assert_eq!(q.pop(), Some('b'));
assert!(q.pop().is_none());
Implementations
impl<T> SegQueue<T>
const fn new() -> SegQueue<T>Creates a new unbounded queue.
Examples
use crossbeam_queue::SegQueue; let q = SegQueue::<i32>::new();fn push(&self, value: T)Pushes back an element to the tail.
Examples
use crossbeam_queue::SegQueue; let q = SegQueue::new(); q.push(10); q.push(20);fn push_mut(&mut self, value: T)Pushes an element to the queue with exclusive mutable access.
Avoids atomic operations and synchronization, assuming no other threads access the queue concurrently.
Examples
use crossbeam_queue::SegQueue; let mut q = SegQueue::new(); q.push_mut(10); q.push_mut(20);fn pop(&self) -> Option<T>Pops the head element from the queue.
If the queue is empty,
Noneis returned.Examples
use crossbeam_queue::SegQueue; let q = SegQueue::new(); q.push(10); q.push(20); assert_eq!(q.pop(), Some(10)); assert_eq!(q.pop(), Some(20)); assert!(q.pop().is_none());fn pop_mut(&mut self) -> Option<T>Pops the head element from the queue using an exclusive reference.
Avoids atomic operations and synchronization, assuming no other threads access the queue concurrently.
If the queue is empty,
Noneis returned.Examples
use crossbeam_queue::SegQueue; let mut q = SegQueue::new(); q.push(10); q.push(20); assert_eq!(q.pop_mut(), Some(10)); assert_eq!(q.pop_mut(), Some(20)); assert!(q.pop_mut().is_none());fn is_empty(&self) -> boolReturns
trueif the queue is empty.Examples
use crossbeam_queue::SegQueue; let q = SegQueue::new(); assert!(q.is_empty()); q.push(1); assert!(!q.is_empty());fn len(&self) -> usizeReturns the number of elements in the queue.
Examples
use crossbeam_queue::SegQueue; let q = SegQueue::new(); assert_eq!(q.len(), 0); q.push(10); assert_eq!(q.len(), 1); q.push(20); assert_eq!(q.len(), 2);
Trait Implementations
impl<T> Debug for SegQueue<T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T> Default for SegQueue<T>
fn default() -> SegQueue<T>
impl<T> Drop for SegQueue<T>
fn drop(&mut self)
impl<T> IntoIterator for SegQueue<T>
type Item = T;type IntoIter = IntoIter<T>;fn into_iter(self) -> Self::IntoIter