Expand description
§enough
Minimal cooperative cancellation trait. Zero dependencies, no_std compatible.
§Which Crate?
- Library authors: Use this crate (
enough) - minimal, zero deps - Application code: Use
almost-enoughfor concrete types
§For Library Authors
Accept impl Stop + 'static in your public API. Internally,
use StopToken
from almost-enough — it handles the Unstoppable optimization
automatically and is the fastest option for real stop types:
use enough::{Stop, StopReason};
pub fn decode(data: &[u8], stop: impl Stop + 'static) -> Result<Vec<u8>, DecodeError> {
// Internally: StopToken::new(stop) erases the type and optimizes
// Unstoppable to a no-op. See almost-enough docs for details.
let mut output = Vec::new();
for (i, chunk) in data.chunks(1024).enumerate() {
if i % 16 == 0 {
stop.check()?;
}
output.extend_from_slice(chunk);
}
Ok(output)
}
#[derive(Debug)]
pub enum DecodeError {
Stopped(StopReason),
InvalidData,
}
impl From<StopReason> for DecodeError {
fn from(r: StopReason) -> Self { DecodeError::Stopped(r) }
}§Zero-Cost When Not Needed
Use Unstoppable when you don’t need cancellation:
use enough::Unstoppable;
// Compiles to nothing - zero runtime cost
// let result = my_codec::decode(&data, Unstoppable);§Implementations
This crate provides only the trait and a zero-cost Unstoppable implementation.
For concrete cancellation primitives (Stopper, StopSource, timeouts, etc.),
see the almost-enough crate.
§Feature Flags
- None (default) - Core trait only,
no_stdcompatible std- Impliesalloc(kept for downstream compatibility)
Structs§
- Unstoppable
- A
Stopimplementation that never stops (no cooperative cancellation).
Enums§
- Stop
Reason - Why an operation was stopped.
Traits§
- Stop
- Cooperative cancellation check.
Type Aliases§
- Never
Deprecated - Type alias for backwards compatibility.