| Crates.io | enough |
| lib.rs | enough |
| version | 0.3.1 |
| created_at | 2026-01-11 00:06:38.93744+00 |
| updated_at | 2026-01-18 07:50:46.727603+00 |
| description | Minimal cooperative cancellation trait for long-running operations |
| homepage | |
| repository | https://github.com/imazen/enough |
| max_upload_size | |
| id | 2034977 |
| size | 15,088 |
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.
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) }
}
use enough::Unstoppable;
// Compiles away completely - zero runtime cost
let result = my_lib::decode(&data, Unstoppable);
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" implementationFor concrete cancellation implementations (Stopper, StopSource, timeouts, etc.), see almost-enough.
no_std core: Stop trait, StopReason, Unstoppablealloc - Adds Box<T> and Arc<T> blanket impls for Stopstd - Implies alloc. Adds std::error::Error impl for StopReasonalmost-enough - All implementations: Stopper, StopSource, ChildStopper, timeouts, combinators, guardsenough-ffi - FFI helpers for C#, Python, Node.jsenough-tokio - Tokio CancellationToken bridgeMIT OR Apache-2.0