7 unstable releases (3 breaking)
| new 0.4.0 | Feb 20, 2026 |
|---|---|
| 0.3.1 | Jan 18, 2026 |
| 0.2.0 | Jan 11, 2026 |
| 0.1.2 | Jan 11, 2026 |
#2237 in Rust patterns
756 downloads per month
Used in 18 crates
(15 directly)
15KB
206 lines
enough
Minimal cooperative cancellation trait 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 enough::{Stop, StopReason};
pub fn decode(data: &[u8], stop: impl Stop) -> Result<Vec<u8>, MyError> {
for (i, chunk) in data.chunks(1024).enumerate() {
if i % 16 == 0 {
stop.check()?; // Returns Err(StopReason) if stopped
}
// process...
}
Ok(vec![])
}
impl From<StopReason> for MyError {
fn from(r: StopReason) -> Self { MyError::Stopped(r) }
}
Zero-Cost Default
use enough::Unstoppable;
// Compiles away completely - zero runtime cost
let result = my_lib::decode(&data, Unstoppable);
What's in This Crate
This crate provides only the core trait and types:
Stop- The cooperative cancellation traitStopReason- Why an operation stopped (Cancelled or TimedOut)Unstoppable- Zero-cost "never stop" implementation
For concrete cancellation implementations (Stopper, StopSource, timeouts, etc.), see almost-enough.
Features
- None (default) -
no_stdcore:Stoptrait,StopReason,Unstoppable alloc- AddsBox<T>andArc<T>blanket impls forStopstd- Impliesalloc(kept for downstream compatibility)
See Also
almost-enough- All implementations:Stopper,StopSource,ChildStopper, timeouts, combinators, guardsenough-ffi- FFI helpers for C#, Python, Node.jsenough-tokio- Tokio CancellationToken bridge
License
MIT OR Apache-2.0