#[batch_task]Expand description
Apply to the BatchTask trait definition, an
impl BatchTask<S [, K]> for T block, or — for less boilerplate — an
inherent impl T { ... } block.
Use as #[cano::task::batch].
Two surface forms are supported on impl blocks:
- Trait-impl form:
#[task::batch] impl BatchTask<S> for T { type Item = I; type ItemOutput = O; ... }— user writes the trait header. The macro async-rewrites theBatchTaskimpl AND emits a companionimpl Task<S> for Tthat delegatesTask::run→run_batch. - Inherent-impl form:
#[task::batch(state = S [, key = K])] impl T { async fn load(..); async fn process_item(..); async fn finish(..); }— the macro builds theimpl BatchTask<S [, K]> for Theader from the attribute args, inferstype Itemfrom the&Tparameter ofprocess_itemandtype ItemOutputfrom its return type, enforces thatload,process_item, andfinishare present (concurrency,item_retry,config,namemay be overridden), and emits the same companionimpl Task<S [, K]> for T.
On a trait definition (#[task::batch] pub trait BatchTask ...) the macro just performs the
async-fn-in-trait rewrite.
Because a blanket impl<B: BatchTask<..>> Task<..> for B would conflict (E0119) with the
analogous blanket impls for the other specialized task traits — a type can implement more than
one — the companion Task impl is generated per-use-site rather than as a blanket.
Task::run always delegates to the ::cano::task::batch::run_batch free function (it is
never inlined into the generated code) because the fan-out loop requires futures_util,
which is not a direct dependency of external callers.