almost-enough
Batteries-included ergonomic extensions for the [enough] cooperative cancellation crate.
This crate provides all the concrete implementations and helpers for working with
stop tokens. It re-exports everything from enough for convenience.
Quick Start
use ;
let stop = new;
let stop2 = stop.clone; // Clone to share
// Pass to operations
assert!;
// Any clone can cancel
stop.cancel;
assert!;
Type Overview
| Type | Feature | Use Case |
|---|---|---|
[Never] |
core | Zero-cost "never stop" |
[StopSource] / [StopRef] |
core | Stack-based, borrowed, zero-alloc |
[FnStop] |
core | Wrap any closure |
[OrStop] |
core | Combine multiple stops |
[Stopper] |
alloc | Default choice - Arc-based, clone to share |
[SyncStopper] |
alloc | Like Stopper with Acquire/Release ordering |
[ChildStopper] |
alloc | Hierarchical parent-child cancellation |
[BoxedStop] |
alloc | Type-erased dynamic dispatch |
[WithTimeout] |
std | Add deadline to any Stop |
StopExt Extension Trait
The [StopExt] trait adds combinator methods to any [Stop] implementation:
use ;
let timeout = new;
let cancel = new;
// Combine: stop if either stops
let combined = timeout.as_ref.or;
assert!;
cancel.cancel;
assert!;
Type Erasure with into_boxed()
Prevent monomorphization explosion at API boundaries:
#
#
#
#
Hierarchical Cancellation with .child()
Create child stops that inherit cancellation from their parent:
#
#
#
#
Stop Guards (RAII Cancellation)
Automatically stop on scope exit unless explicitly disarmed:
#
#
#
#
Feature Flags
std(default) - Full functionality including timeoutsalloc- Arc-based types,into_boxed(),child(),StopDropRoll- None - Core trait and stack-based types only