Skip to main content

CloneStop

Trait CloneStop 

Source
pub trait CloneStop:
    Stop
    + Clone
    + 'static { }
Expand description

Trait alias for stop tokens that can be cloned and sent across threads.

This is Stop + Clone + 'static — the minimum needed to clone a stop token and send it to other threads. Since Stop already requires Send + Sync, CloneStop types are fully thread-safe.

Use impl CloneStop in public API signatures when you need to clone the stop token, then erase with StopToken internally:

use almost_enough::{CloneStop, StopToken, Stop};

pub fn parallel_work(stop: impl CloneStop) {
    let stop = StopToken::new(stop);
    let s2 = stop.clone(); // Arc increment
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Stop + Clone + 'static> CloneStop for T

Blanket implementation: any Stop + Clone + 'static is CloneStop.