[go: up one dir, main page]

pub struct Worker<T, B: Buffer<T>> { /* private fields */ }
Expand description

Handle for single-threaded LIFO push and pop operations.

Implementations

Creates a new queue and returns a Worker handle.

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.

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.

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.

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.

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.

Attempts to pop one item from the tail of the queue.

This returns None if the queue is empty.

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:

  1. no item was stolen, either because the queue is empty or N is 0,
  2. a concurrent stealing operation is ongoing.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.