Skip to main content

hearth_graph/
cancel.rs

1/// Host-provided cancellation signal.
2pub trait CancelSignal: Sync {
3    /// Returns `true` when the current operation should stop.
4    fn is_cancelled(&self) -> bool;
5}
6
7impl<F> CancelSignal for F
8where
9    F: Fn() -> bool + Sync,
10{
11    fn is_cancelled(&self) -> bool {
12        self()
13    }
14}
15
16/// Cancellation signal that never requests cancellation.
17#[derive(Clone, Copy, Debug, Default)]
18pub struct NeverCancelled;
19
20impl CancelSignal for NeverCancelled {
21    fn is_cancelled(&self) -> bool {
22        false
23    }
24}