pub trait BatchExecutor: Send + Sync {
// Required method
fn execute_with_count<T, E, I>(
&self,
tasks: I,
count: usize,
) -> Result<BatchOutcome<E>, BatchExecutionError<E>>
where I: IntoIterator<Item = T>,
T: Runnable<E> + Send,
E: Send;
// Provided methods
fn execute<T, E, I>(
&self,
tasks: I,
) -> Result<BatchOutcome<E>, BatchExecutionError<E>>
where I: IntoIterator<Item = T>,
I::IntoIter: ExactSizeIterator,
T: Runnable<E> + Send,
E: Send { ... }
fn call<C, R, E, I>(
&self,
tasks: I,
) -> Result<BatchCallResult<R, E>, BatchExecutionError<E>>
where I: IntoIterator<Item = C>,
I::IntoIter: ExactSizeIterator,
C: Callable<R, E> + Send,
R: Send,
E: Send { ... }
fn call_with_count<C, R, E, I>(
&self,
tasks: I,
count: usize,
) -> Result<BatchCallResult<R, E>, BatchExecutionError<E>>
where I: IntoIterator<Item = C>,
C: Callable<R, E> + Send,
R: Send,
E: Send { ... }
fn for_each<Item, E, I, F>(
&self,
items: I,
action: F,
) -> Result<BatchOutcome<E>, BatchExecutionError<E>>
where I: IntoIterator<Item = Item>,
I::IntoIter: ExactSizeIterator,
Item: Send,
F: Fn(Item) -> Result<(), E> + Send + Sync,
E: Send { ... }
fn for_each_with_count<Item, E, I, F>(
&self,
items: I,
count: usize,
action: F,
) -> Result<BatchOutcome<E>, BatchExecutionError<E>>
where I: IntoIterator<Item = Item>,
Item: Send,
F: Fn(Item) -> Result<(), E> + Send + Sync,
E: Send { ... }
}Expand description
Executes batches of fallible tasks.
Implementations consume the supplied iterator once, execute every observed
task unless an explicitly declared count is exceeded, and return a
BatchOutcome containing task-level successes, failures, panics, and
elapsed time.
use qubit_batch::{
BatchExecutor,
SequentialBatchExecutor,
};
let outcome = SequentialBatchExecutor::new()
.for_each([1, 2, 3], |value| {
assert!(value > 0);
Ok::<(), &'static str>(())
})
.expect("array length should be exact");
assert!(outcome.is_success());Required Methods§
Sourcefn execute_with_count<T, E, I>(
&self,
tasks: I,
count: usize,
) -> Result<BatchOutcome<E>, BatchExecutionError<E>>
fn execute_with_count<T, E, I>( &self, tasks: I, count: usize, ) -> Result<BatchOutcome<E>, BatchExecutionError<E>>
Executes a batch of runnable tasks with an explicit declared count.
§Parameters
tasks- Task source for the batch. It may be eager or lazy.count- Declared number of tasks expected fromtasks.
§Returns
Ok(BatchOutcome) when the declared task count matches the source, or
Err(BatchExecutionError) when the source yields fewer or more tasks
than declared.
§Errors
Returns BatchExecutionError when the source task count does not
match count.
§Panics
Panics from individual tasks are captured in BatchOutcome.
Panics from the configured
qubit_progress::reporter::ProgressReporter are propagated to the
caller.
Provided Methods§
Sourcefn execute<T, E, I>(
&self,
tasks: I,
) -> Result<BatchOutcome<E>, BatchExecutionError<E>>
fn execute<T, E, I>( &self, tasks: I, ) -> Result<BatchOutcome<E>, BatchExecutionError<E>>
Executes a batch of runnable tasks whose iterator exposes an exact length.
§Parameters
tasks- Task source for the batch. Its iterator must report the remaining task count exactly.
§Returns
The result returned by Self::execute_with_count after deriving the
declared count from the iterator length.
§Errors
Returns BatchExecutionError only if the iterator violates its exact
length contract while being consumed.
§Panics
Panics from individual tasks are captured in BatchOutcome.
Panics from the configured
qubit_progress::reporter::ProgressReporter are propagated to the
caller.
Sourcefn call<C, R, E, I>(
&self,
tasks: I,
) -> Result<BatchCallResult<R, E>, BatchExecutionError<E>>where
I: IntoIterator<Item = C>,
I::IntoIter: ExactSizeIterator,
C: Callable<R, E> + Send,
R: Send,
E: Send,
fn call<C, R, E, I>(
&self,
tasks: I,
) -> Result<BatchCallResult<R, E>, BatchExecutionError<E>>where
I: IntoIterator<Item = C>,
I::IntoIter: ExactSizeIterator,
C: Callable<R, E> + Send,
R: Send,
E: Send,
Executes callable tasks whose iterator exposes an exact length.
§Parameters
tasks- Callable task source for the batch. Its iterator must report the remaining callable count exactly.
§Returns
A BatchCallResult containing the normal execution summary plus
optional success values indexed by callable position.
§Errors
Returns BatchExecutionError only if the iterator violates its exact
length contract while being consumed.
§Panics
Panics from individual callables are captured in the execution result.
Panics from the configured
qubit_progress::reporter::ProgressReporter are propagated to the
caller.
Sourcefn call_with_count<C, R, E, I>(
&self,
tasks: I,
count: usize,
) -> Result<BatchCallResult<R, E>, BatchExecutionError<E>>
fn call_with_count<C, R, E, I>( &self, tasks: I, count: usize, ) -> Result<BatchCallResult<R, E>, BatchExecutionError<E>>
Executes callable tasks with an explicit declared count and collects success values by index.
§Parameters
tasks- Callable task source for the batch.count- Declared number of callables expected fromtasks.
§Returns
A BatchCallResult containing the normal execution summary plus
optional success values indexed by callable position.
§Errors
Returns BatchExecutionError when the source callable count does not
match count.
§Panics
Panics from individual callables are captured in the execution result.
Panics from the configured
qubit_progress::reporter::ProgressReporter are propagated to the
caller.
Sourcefn for_each<Item, E, I, F>(
&self,
items: I,
action: F,
) -> Result<BatchOutcome<E>, BatchExecutionError<E>>where
I: IntoIterator<Item = Item>,
I::IntoIter: ExactSizeIterator,
Item: Send,
F: Fn(Item) -> Result<(), E> + Send + Sync,
E: Send,
fn for_each<Item, E, I, F>(
&self,
items: I,
action: F,
) -> Result<BatchOutcome<E>, BatchExecutionError<E>>where
I: IntoIterator<Item = Item>,
I::IntoIter: ExactSizeIterator,
Item: Send,
F: Fn(Item) -> Result<(), E> + Send + Sync,
E: Send,
Applies action to every item whose iterator exposes an exact length.
§Parameters
items- Item source to transform into runnable tasks.action- Fallible action applied to each item.
§Returns
The result returned by Self::for_each_with_count after deriving the
declared count from the iterator length.
§Errors
Returns BatchExecutionError only if the iterator violates its exact
length contract while being consumed.
Sourcefn for_each_with_count<Item, E, I, F>(
&self,
items: I,
count: usize,
action: F,
) -> Result<BatchOutcome<E>, BatchExecutionError<E>>
fn for_each_with_count<Item, E, I, F>( &self, items: I, count: usize, action: F, ) -> Result<BatchOutcome<E>, BatchExecutionError<E>>
Applies action to every item using an explicit declared count.
§Parameters
items- Item source to transform into runnable tasks.count- Declared number of items expected fromitems.action- Fallible action applied to each item.
§Returns
The result returned by Self::execute_with_count for the derived task
batch.
§Errors
Returns BatchExecutionError when the source item count does not
match count.
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.