pub trait WorkerMethods<T, R> {
Show 13 methods
// Required methods
fn add_task(&self, task: T);
fn add_tasks(&self, tasks: impl IntoIterator<Item = T>);
fn get(&self) -> Option<R>;
fn get_blocking(&self) -> Option<R>;
fn cancel_tasks(&self);
fn pending_tasks(&self) -> usize;
// Provided methods
fn get_iter(&self) -> impl Iterator<Item = R> { ... }
fn get_iter_blocking(&self) -> impl Iterator<Item = R> { ... }
fn get_vec(&self) -> Vec<R> { ... }
fn get_vec_blocking(&self) -> Vec<R> { ... }
fn get_buffered(&self, buffer: &mut [R]) -> usize { ... }
fn get_buffered_blocking(&self, buffer: &mut [R]) -> usize { ... }
fn reset(&self) { ... }
}Expand description
Methods for interacting with a worker.
Required Methods§
Sourcefn add_task(&self, task: T)
fn add_task(&self, task: T)
Add a task to the end of the queue. The task will be processed by one of the worker threads.
Sourcefn add_tasks(&self, tasks: impl IntoIterator<Item = T>)
fn add_tasks(&self, tasks: impl IntoIterator<Item = T>)
Add multiple tasks to the end of the queue. The tasks will be processed by the worker threads.
Sourcefn get(&self) -> Option<R>
fn get(&self) -> Option<R>
Return the next result. If no result is available, return None. This function will not block.
Sourcefn get_blocking(&self) -> Option<R>
fn get_blocking(&self) -> Option<R>
Return the next result. If no result is available block until a result is available. If no tasks are pending, return None.
Sourcefn cancel_tasks(&self)
fn cancel_tasks(&self)
Cancel all tasks.
Sourcefn pending_tasks(&self) -> usize
fn pending_tasks(&self) -> usize
Return the number of pending tasks. This only includes tasks that have been added to the queue but have not started processing.
Provided Methods§
Sourcefn get_iter(&self) -> impl Iterator<Item = R>
fn get_iter(&self) -> impl Iterator<Item = R>
Return an iterator over all available results. This function will not block.
Sourcefn get_iter_blocking(&self) -> impl Iterator<Item = R>
fn get_iter_blocking(&self) -> impl Iterator<Item = R>
Returns an iterator over all results. This function will block until all tasks have been processed.
Sourcefn get_vec(&self) -> Vec<R>
fn get_vec(&self) -> Vec<R>
Receive all available results and return them in a vector. This function will not block.
Sourcefn get_vec_blocking(&self) -> Vec<R>
fn get_vec_blocking(&self) -> Vec<R>
Block until all tasks have been processed and return all results in a vector. This function will block until all tasks have been processed.
Sourcefn get_buffered(&self, buffer: &mut [R]) -> usize
fn get_buffered(&self, buffer: &mut [R]) -> usize
Write available results into the buffer and return the number of results written. If the buffer is too small to hold all available results, the remaining results will be left in the queue. This function will not block.
Sourcefn get_buffered_blocking(&self, buffer: &mut [R]) -> usize
fn get_buffered_blocking(&self, buffer: &mut [R]) -> usize
Write all results into the buffer and return the number of results written. If the buffer is too small to hold all results, the remaining results will be left in the queue. This function will block until all tasks have been processed or the buffer is full.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.