BoxedStop

Struct BoxedStop 

Source
pub struct BoxedStop(/* private fields */);
Expand description

A heap-allocated Stop implementation.

This type provides dynamic dispatch for Stop, avoiding monomorphization bloat when you don’t need the performance of generics.

§Example

use almost_enough::{BoxedStop, StopSource, Stopper, Never, Stop};

fn process(stop: BoxedStop) {
    for i in 0..1000 {
        if i % 100 == 0 && stop.should_stop() {
            return;
        }
        // process...
    }
}

// Works with any Stop implementation
process(BoxedStop::new(Never));
process(BoxedStop::new(StopSource::new()));
process(BoxedStop::new(Stopper::new()));

Implementations§

Source§

impl BoxedStop

Source

pub fn new<T: Stop + 'static>(stop: T) -> Self

Create a new boxed stop from any Stop implementation.

Trait Implementations§

Source§

impl Debug for BoxedStop

Source§

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

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

impl Stop for BoxedStop

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.