pub trait Cancellation: Send + Sync {
// Required method
fn is_cancelled(&self) -> bool;
}Expand description
Trait for cancellation predicates.
A blanket impl covers any Fn() -> bool + Send + Sync, so the common case
is a closure. The single most common adapter is an Arc<AtomicBool> shared
with a GUI “Cancel” button:
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use sheets_diff::DiffOptions;
let cancel_flag = Arc::new(AtomicBool::new(false));
let flag = cancel_flag.clone();
let opts = DiffOptions::builder()
.cancellation(move || flag.load(Ordering::Relaxed))
.build()
.unwrap();
// Setting `cancel_flag` to true from another thread causes the next
// cancellation check to abort the diff with `SheetsDiffError::Cancelled`.§Cancellation latency
is_cancelled() is polled once before each sheet pair, and at an
interval inside a sheet’s own processing — every 50,000 cells, in both
the read phase and the compare phase. On the largest single sheet this
crate’s own benchmark ladder covers (300,000 cells), that bounds
worst-case latency to roughly 100 ms; see docs/src/maintainers/performance.md
for the measured overhead of this polling, with and without a
Cancellation configured.
This changed in M7 Handoff 03. Before it, is_cancelled() was polled
only once before each sheet pair — on a workbook with many sheets,
cancellation was observed promptly at the next sheet boundary, but on a
single sheet (the ordinary shape of a spreadsheet) there was no next
checkpoint, so a comparison ran to completion and returned Ok no matter
when cancellation was requested. That gap is closed: a single-sheet
workbook large enough to cross a polling interval is now cancellable
mid-sheet, in both phases. Setting a max_cells_read / max_cells_compared
bound remains useful for a hard resource ceiling, but is no longer the
only way to get sub-sheet cancellation latency.
Required Methods§
fn is_cancelled(&self) -> bool
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".