Skip to main content

stepped_task

Attribute Macro stepped_task 

Source
#[stepped_task]
Expand description

Apply to the SteppedTask trait definition, an impl SteppedTask<S [, K]> for T block, or — for less boilerplate — an inherent impl T { ... } block.

Use as #[cano::task::stepped].

Two surface forms on impl blocks:

  1. Trait-impl form: #[task::stepped] impl SteppedTask<S> for T { type Cursor = C; async fn step(..) { ... } } — user writes the trait header. The macro async-rewrites the SteppedTask impl AND emits a companion impl Task<S> for T that delegates Task::run via the run_stepped helper.
  2. Inherent-impl form: #[task::stepped(state = S [, key = K])] impl T { async fn step(..) { ... } } — the macro builds the impl SteppedTask<S [, K]> for T header from the attribute args, infers type Cursor from the Option<C> third parameter of step, enforces that step is present (config / name may be overridden), and emits the same companion impl Task<S [, K]> for T.

On a trait definition (#[task::stepped] pub trait SteppedTask ...) the macro just performs the async-fn-in-trait rewrite.

Because a blanket impl<S: SteppedTask<..>> Task<..> for S 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.

The default config() injected by the inherent form is [TaskConfig::default()] (exponential backoff with 3 retries).