#[task]Expand description
Apply to impl Task for ... blocks (or the Task trait definition itself).
Rewrites every async fn method into a method returning
Pin<Box<dyn Future<Output = ...> + Send + 'async_trait>>, the same shape
async-trait produces. This makes the methods callable through
dyn Task<...>.
Use as #[cano::task].
Two surface forms are supported:
- Trait-impl form:
#[task] impl Task<S> for X { ... }โ user writes the trait header. - Inherent-impl form:
#[task(state = S [, key = K])] impl X { ... }โ user writes only the inherent block; the macro builds the trait header and enforces that exactly one ofrun/run_bareis present.
For compensatable (saga) tasks, use #[cano::saga::task]
instead.
ยงExample
โ
use cano::task;
#[task(state = MyState)]
impl MyTask {
async fn run_bare(&self) -> Result<TaskResult<MyState>, CanoError> {
Ok(TaskResult::Single(MyState::Done))
}
}