ultra_batch/
executor.rs

1use std::fmt::Display;
2use std::future::Future;
3
4/// A trait for using a batch of values to execute some operation, such
5/// as a bulk insertion in a datastore. An `Executor` will be given an
6/// array of values and should handle each value, then return a result for
7/// each. Implementing `Executor` will allow operations to be batched by
8/// using a [`BatchExecutor`](crate::BatchExecutor). See the [`BatchExecutor`](crate::BatchExecutor)
9/// docs for details about batching and error semantics.
10pub trait Executor {
11    /// The input value provided by the caller to do something.
12    type Value: Send;
13
14    /// The output value returned by the executor back to the caller for each
15    /// input value.
16    type Result: Send;
17
18    /// The error indicating that executing a batch failed.
19    type Error: Display;
20
21    /// Execute the operation for each value in the batch, returning a result
22    /// for each value. If `Ok(_)` is returned, a `Vec` should be returned,
23    /// where each element corresponds to the result of the input value at
24    /// the same index. If no element is present for a given input value,
25    /// then the caller will not receive a value. If `Err(_)` is returned,
26    /// then the caller waiting on the batch will receive an [`ExecuteError::ExecutorError`](crate::ExecuteError::ExecutorError).
27    fn execute(
28        &self,
29        values: Vec<Self::Value>,
30    ) -> impl Future<Output = Result<Vec<Self::Result>, Self::Error>> + Send;
31}