enough
Minimal cooperative cancellation for Rust.
A minimal, no_std trait for cooperative cancellation. Zero dependencies.
StopReason is 1 byte and check() compiles to a single boolean read from the stack.
For Library Authors
Accept impl Stop in your functions:
use ;
For Application Developers
[]
= { = "0.1", = ["std"] }
use ;
use Duration;
let stop = new;
let timed = stop.clone.with_timeout;
// Pass to library
let result = decode;
// Or cancel manually
stop.cancel;
Zero-Cost Default
use Never;
// Compiles away completely - zero runtime cost
let result = decode;
Features
- None (default) -
no_stdcore:Stoptrait,Never,StopSource,FnStop,OrStop alloc- AddsStopper,SyncStopper,ChildStopper,BoxedStop+Box<T>/Arc<T>implsstd- Impliesalloc. Adds timeouts (TimeoutExt,WithTimeout)
Type Overview
| Type | Feature | Use Case |
|---|---|---|
Never |
core | Zero-cost "never stop" |
StopSource / StopRef |
core | Stack-based, borrowed, Relaxed ordering |
FnStop |
core | Wrap any closure |
OrStop |
core | Combine multiple stop sources |
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 |
See Also
almost-enough- Ergonomic extensions (.or(),.into_boxed(),.child(), guards)enough-ffi- FFI helpers for C#, Python, Node.jsenough-tokio- Tokio CancellationToken bridge
Note: Ergonomic extensions live in almost-enough until stabilized from use and feedback.
License
MIT OR Apache-2.0