StopSource

Struct StopSource 

Source
pub struct StopSource { /* private fields */ }
Expand description

A stack-based cancellation source.

This is a zero-allocation cancellation primitive. The source owns the atomic and can issue borrowed references via as_ref().

§Example

use almost_enough::{StopSource, Stop};

let source = StopSource::new();
let stop = source.as_ref();

// Check in your operation
assert!(!stop.should_stop());

// Cancel when needed
source.cancel();
assert!(stop.should_stop());

§Const Construction

StopSource can be created in const context:

use almost_enough::StopSource;

static GLOBAL_STOP: StopSource = StopSource::new();

Implementations§

Source§

impl StopSource

Source

pub const fn new() -> Self

Create a new cancellation source.

Source

pub const fn cancelled() -> Self

Create a source that is already cancelled.

Useful for testing or when you want to signal immediate stop.

Source

pub fn cancel(&self)

Signal all references to stop.

This is idempotent - calling it multiple times has no additional effect.

Source

pub fn is_cancelled(&self) -> bool

Check if this source has been cancelled.

Source

pub fn as_ref(&self) -> StopRef<'_>

Get a borrowed reference to pass to operations.

The reference borrows from this source, so it cannot outlive it. For owned stops, use Stopper.

Source

pub fn token(&self) -> StopRef<'_>

👎Deprecated since 0.1.0: use as_ref() instead

Alias for as_ref() for migration from AtomicStop.

Trait Implementations§

Source§

impl Debug for StopSource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StopSource

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Stop for StopSource

Source§

fn check(&self) -> Result<(), StopReason>

Check if the operation should stop. Read more
Source§

fn should_stop(&self) -> bool

Returns true if the operation should stop. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> StopExt for T
where T: Stop,

Source§

fn or<S: Stop>(self, other: S) -> OrStop<Self, S>

Combine this stop with another, stopping if either stops. Read more
Source§

fn into_boxed(self) -> BoxedStop
where Self: 'static,

Convert this stop into a boxed trait object. Read more
Source§

fn child(&self) -> ChildStopper
where Self: Clone + 'static,

Create a child stop that inherits cancellation from this stop. Read more
Source§

impl<T> TimeoutExt for T
where T: Stop,

Source§

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>

Add an absolute deadline to this stop. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.