pub struct ArrayQueue<T> { /* fields omitted */ }
A bounded multi-producer multi-consumer queue.
This queue allocates a fixed-capacity buffer on construction, which is used to store pushed
elements. The queue cannot hold more elements that the buffer allows. Attempting to push an
element into a full queue will fail. Having a buffer allocated upfront makes this queue a bit
faster than SegQueue
.
use crossbeam_queue::{ArrayQueue, PushError};
let q = ArrayQueue::new(2);
assert_eq!(q.push('a'), Ok(()));
assert_eq!(q.push('b'), Ok(()));
assert_eq!(q.push('c'), Err(PushError('c')));
assert_eq!(q.pop(), Ok('a'));
Creates a new bounded queue with the given capacity.
Panics if the capacity is zero.
use crossbeam_queue::ArrayQueue;
let q = ArrayQueue::<i32>::new(100);
Attempts to push an element into the queue.
If the queue is full, the element is returned back as an error.
use crossbeam_queue::{ArrayQueue, PushError};
let q = ArrayQueue::new(1);
assert_eq!(q.push(10), Ok(()));
assert_eq!(q.push(20), Err(PushError(20)));
Attempts to pop an element from the queue.
If the queue is empty, an error is returned.
use crossbeam_queue::{ArrayQueue, PopError};
let q = ArrayQueue::new(1);
assert_eq!(q.push(10), Ok(()));
assert_eq!(q.pop(), Ok(10));
assert_eq!(q.pop(), Err(PopError));
Returns the capacity of the queue.
use crossbeam_queue::{ArrayQueue, PopError};
let q = ArrayQueue::<i32>::new(100);
assert_eq!(q.capacity(), 100);
Returns true
if the queue is empty.
use crossbeam_queue::{ArrayQueue, PopError};
let q = ArrayQueue::new(100);
assert!(q.is_empty());
q.push(1).unwrap();
assert!(!q.is_empty());
Returns true
if the queue is full.
use crossbeam_queue::{ArrayQueue, PopError};
let q = ArrayQueue::new(1);
assert!(!q.is_full());
q.push(1).unwrap();
assert!(q.is_full());
Returns the number of elements in the queue.
use crossbeam_queue::{ArrayQueue, PopError};
let q = ArrayQueue::new(100);
assert_eq!(q.len(), 0);
q.push(10).unwrap();
assert_eq!(q.len(), 1);
q.push(20).unwrap();
assert_eq!(q.len(), 2);
Executes the destructor for this type. Read more
Formats the value using the given formatter. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)