pub struct Worker<T, B: Buffer<T>> { /* private fields */ }Expand description
Handle for single-threaded LIFO push and pop operations.
Implementations
sourceimpl<T, B: Buffer<T>> Worker<T, B>
impl<T, B: Buffer<T>> Worker<T, B>
sourcepub fn stealer(&self) -> Stealer<T, B>
pub fn stealer(&self) -> Stealer<T, B>
Creates a new Stealer handle associated to this Worker.
An arbitrary number of Stealer handles can be created, either using
this method or cloning an existing Stealer handle.
sourcepub fn spare_capacity(&self) -> usize
pub fn spare_capacity(&self) -> usize
Returns the number of items that can be successfully pushed onto the queue.
Note that that the spare capacity may be underestimated due to concurrent stealing operations.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the queue is empty.
Note that the queue size is somewhat ill-defined in a multi-threaded
context, but it is warranted that if is_empty() returns true, a
subsequent call to pop() will fail.
sourcepub fn push(&self, item: T) -> Result<(), T>
pub fn push(&self, item: T) -> Result<(), T>
Attempts to push one item at the tail of the queue.
Errors
This will fail if the queue is full, in which case the item is returned as the error field.
sourcepub fn extend<I: IntoIterator<Item = T>>(&self, iter: I)
pub fn extend<I: IntoIterator<Item = T>>(&self, iter: I)
Attempts to push the content of an iterator at the tail of the queue.
It is the responsibility of the caller to ensure that there is enough
spare capacity to accommodate all iterator items, for instance by
calling [Worker::spare_capacity] beforehand. Otherwise, the iterator
is dropped while still holding the excess items.
sourcepub fn pop(&self) -> Option<T>
pub fn pop(&self) -> Option<T>
Attempts to pop one item from the tail of the queue.
This returns None if the queue is empty.
sourcepub fn drain<C>(&self, count_fn: C) -> Result<Drain<'_, T, B>, StealError>where
C: FnMut(usize) -> usize,
pub fn drain<C>(&self, count_fn: C) -> Result<Drain<'_, T, B>, StealError>where
C: FnMut(usize) -> usize,
Returns an iterator that steals items from the head of the queue.
The returned iterator steals up to N items, where N is specified by
a closure which takes as argument the total count of items available for
stealing. Upon success, the number of items ultimately stolen can be
from 1 to N, depending on the number of available items.
Beware
All items stolen by the iterator should be moved out as soon as
possible, because until then or until the iterator is dropped, all
concurrent stealing operations will fail with StealError::Busy.
Leaking
If the iterator is leaked before all stolen items have been moved out,
subsequent stealing operations will permanently fail with
StealError::Busy.
Errors
An error is returned in the following cases:
- no item was stolen, either because the queue is empty or
Nis 0, - a concurrent stealing operation is ongoing.
Trait Implementations
impl<T, B: Buffer<T>> RefUnwindSafe for Worker<T, B>
impl<T: Send, B: Buffer<T>> Send for Worker<T, B>
impl<T, B: Buffer<T>> UnwindSafe for Worker<T, B>
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more