Stop

Trait Stop 

Source
pub trait Stop: Send + Sync {
    // Required method
    fn check(&self) -> Result<(), StopReason>;

    // Provided method
    fn should_stop(&self) -> bool { ... }
}
Expand description

Cooperative cancellation check.

Implement this trait for custom cancellation sources. The implementation must be thread-safe (Send + Sync) to support parallel processing and async runtimes.

§Example Implementation

use enough::{Stop, StopReason};
use core::sync::atomic::{AtomicBool, Ordering};

pub struct MyStop<'a> {
    cancelled: &'a AtomicBool,
}

impl Stop for MyStop<'_> {
    fn check(&self) -> Result<(), StopReason> {
        if self.cancelled.load(Ordering::Relaxed) {
            Err(StopReason::Cancelled)
        } else {
            Ok(())
        }
    }
}

Required Methods§

Source

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

Check if the operation should stop.

Returns Ok(()) to continue, Err(StopReason) to stop.

Call this periodically in long-running loops. The frequency depends on your workload - typically every 16-1000 iterations is reasonable.

Provided Methods§

Source

fn should_stop(&self) -> bool

Returns true if the operation should stop.

Convenience method for when you want to handle stopping yourself rather than using the ? operator.

Implementations on Foreign Types§

Source§

impl<T> Stop for &T
where T: Stop + ?Sized,

Source§

impl<T> Stop for &mut T
where T: Stop + ?Sized,

Implementors§

Source§

impl Stop for BoxedStop

Source§

impl Stop for ChildStopper

Source§

impl Stop for Never

Source§

impl Stop for StopRef<'_>

Source§

impl Stop for StopSource

Source§

impl Stop for Stopper

Source§

impl Stop for SyncStopper

Source§

impl<A: Stop, B: Stop> Stop for OrStop<A, B>

Source§

impl<F> Stop for FnStop<F>
where F: Fn() -> bool + Send + Sync,

Source§

impl<T: Stop> Stop for WithTimeout<T>