Struct crossbeam_queue::SegQueue
source · [−]pub struct SegQueue<T> { /* private fields */ }
Expand description
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::{PopError, SegQueue};
let q = SegQueue::new();
q.push('a');
q.push('b');
assert_eq!(q.pop(), Ok('a'));
assert_eq!(q.pop(), Ok('b'));
assert_eq!(q.pop(), Err(PopError));
Implementations
sourceimpl<T> SegQueue<T>
impl<T> SegQueue<T>
sourcepub fn new() -> SegQueue<T>
pub fn new() -> SegQueue<T>
Creates a new unbounded queue.
Examples
use crossbeam_queue::SegQueue;
let q = SegQueue::<i32>::new();
sourcepub fn push(&self, value: T)
pub fn push(&self, value: T)
Pushes an element into the queue.
Examples
use crossbeam_queue::SegQueue;
let q = SegQueue::new();
q.push(10);
q.push(20);
sourcepub fn pop(&self) -> Result<T, PopError>
pub fn pop(&self) -> Result<T, PopError>
Pops an element from the queue.
If the queue is empty, an error is returned.
Examples
use crossbeam_queue::{PopError, SegQueue};
let q = SegQueue::new();
q.push(10);
assert_eq!(q.pop(), Ok(10));
assert_eq!(q.pop(), Err(PopError));
Trait Implementations
impl<T: Send> Send for SegQueue<T>
impl<T: Send> Sync for SegQueue<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for SegQueue<T> where
T: RefUnwindSafe,
impl<T> Unpin for SegQueue<T> where
T: Unpin,
impl<T> !UnwindSafe for SegQueue<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more