pub struct StopToken { /* private fields */ }Expand description
A shared-ownership Stop implementation with cheap Clone.
Wraps any Stop in an Arc for shared ownership across threads.
Cloning is an atomic increment — no heap allocation.
§Indirection Collapsing
StopToken::new() detects when you pass another StopToken and unwraps
it instead of double-wrapping. No-op stops (Unstoppable) are stored
as None — check() short-circuits without any vtable dispatch.
§Example
use almost_enough::{StopToken, Stopper, Stop, StopReason};
let stopper = Stopper::new();
let stop = StopToken::new(stopper.clone());
let stop2 = stop.clone(); // cheap Arc clone
stopper.cancel();
assert!(stop.should_stop());
assert!(stop2.should_stop()); // both see cancellationImplementations§
Source§impl StopToken
impl StopToken
Sourcepub fn new<T: Stop + 'static>(stop: T) -> Self
pub fn new<T: Stop + 'static>(stop: T) -> Self
Create a new StopToken from any Stop implementation.
If stop is already a StopToken, it is unwrapped instead of
double-wrapping (no extra indirection).
Sourcepub fn from_arc<T: Stop + 'static>(arc: Arc<T>) -> Self
pub fn from_arc<T: Stop + 'static>(arc: Arc<T>) -> Self
Create a StopToken from an existing Arc<T> without re-wrapping.
use almost_enough::{StopToken, Stopper, Stop};
use std::sync::Arc;
let stopper = Arc::new(Stopper::new());
let stop = StopToken::from_arc(stopper);
assert!(!stop.should_stop());Trait Implementations§
Source§impl From<Stopper> for StopToken
Zero-cost conversion: reuses the Stopper’s Arc. Direct atomic dispatch, no vtable.
impl From<Stopper> for StopToken
Zero-cost conversion: reuses the Stopper’s Arc. Direct atomic dispatch, no vtable.
Source§impl From<SyncStopper> for StopToken
Zero-cost conversion: reuses the SyncStopper’s Arc. Direct atomic dispatch.
impl From<SyncStopper> for StopToken
Zero-cost conversion: reuses the SyncStopper’s Arc. Direct atomic dispatch.
Source§fn from(stopper: SyncStopper) -> Self
fn from(stopper: SyncStopper) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for StopToken
impl !RefUnwindSafe for StopToken
impl Send for StopToken
impl Sync for StopToken
impl Unpin for StopToken
impl UnsafeUnpin for StopToken
impl !UnwindSafe for StopToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DebouncedTimeoutExt for Twhere
T: Stop,
impl<T> DebouncedTimeoutExt for Twhere
T: Stop,
Source§fn with_debounced_timeout(self, duration: Duration) -> DebouncedTimeout<Self>
fn with_debounced_timeout(self, duration: Duration) -> DebouncedTimeout<Self>
Add a debounced timeout to this stop. Read more
Source§fn with_debounced_deadline(self, deadline: Instant) -> DebouncedTimeout<Self>
fn with_debounced_deadline(self, deadline: Instant) -> DebouncedTimeout<Self>
Add a debounced timeout with an absolute deadline.
Source§impl<T> StopExt for Twhere
T: Stop,
impl<T> StopExt for Twhere
T: Stop,
Source§impl<T> TimeoutExt for Twhere
T: Stop,
impl<T> TimeoutExt for Twhere
T: Stop,
Source§fn with_timeout(self, duration: Duration) -> WithTimeout<Self>
fn with_timeout(self, duration: Duration) -> WithTimeout<Self>
Add a timeout to this stop. Read more
Source§fn with_deadline(self, deadline: Instant) -> WithTimeout<Self>
fn with_deadline(self, deadline: Instant) -> WithTimeout<Self>
Add an absolute deadline to this stop. Read more