pub struct StopOnly<'a> { /* private fields */ }Expand description
Cancellation without progress: a pulse made from any Stop.
For an application that holds a cancellation token, such as a Stopper or
a deadline, and calls a library that takes &dyn Pulse. Every phase the
library plans checks the same stop; reports go nowhere, and plans are only
validated. An owned stop can be shared with spawned work; a
borrowed one serves scoped work and refuses to be shared.
use how_far::{prelude::*, PhaseSpec, Stages, StopOnly, StopReason, Total};
// A library that knows nothing about the caller's token.
fn encode(rows: u64, pulse: &dyn Pulse) -> Result<(), StopReason> {
Stages::new(pulse, &[PhaseSpec::new("rows", 1, Total::Exact(rows))])
.complete_with(|stages| stages.run(|stage| {
for _ in 0..rows {
stage.step(1)?;
}
Ok(())
}))
}
struct Cancelled;
impl Stop for Cancelled {
fn check(&self) -> Result<(), StopReason> {
Err(StopReason::Cancelled)
}
}
assert_eq!(encode(8, &StopOnly::new(Cancelled)), Err(StopReason::Cancelled));
assert_eq!(encode(8, &StopOnly::borrowed(&how_far::Unstoppable)), Ok(()));Implementations§
Source§impl<'a> StopOnly<'a>
impl<'a> StopOnly<'a>
Sourcepub fn borrowed(stop: &'a dyn Stop) -> Self
pub fn borrowed(stop: &'a dyn Stop) -> Self
Borrow stop, without allocating. Pulse::share then fails with
PlanError::NotShareable, since the view could outlive the borrow.
Trait Implementations§
Source§impl Pulse for StopOnly<'_>
impl Pulse for StopOnly<'_>
Source§fn set_total(&self, _: Total) -> Result<(), PlanError>
fn set_total(&self, _: Total) -> Result<(), PlanError>
Nobody observes the total, so a revision is accepted and discarded.
Source§fn split(
&self,
_: Execution,
parts: &[PhaseSpec<'_>],
) -> Result<Vec<Child<'_>>, PlanError>
fn split( &self, _: Execution, parts: &[PhaseSpec<'_>], ) -> Result<Vec<Child<'_>>, PlanError>
Split this phase into weighted children, in declared order. Read more
Share all pulse capabilities with owned work, but never completion rights. Read more
Source§fn record_issue(&self, _error: PlanError)
fn record_issue(&self, _error: PlanError)
Record a reporting-protocol problem for optional diagnostics. This never
changes cancellation or the operation’s return value. Ordinary sinks may
ignore it; diagnostic wrappers retain bounded evidence.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for StopOnly<'a>
impl<'a> !UnwindSafe for StopOnly<'a>
impl<'a> Freeze for StopOnly<'a>
impl<'a> Send for StopOnly<'a>
impl<'a> Sync for StopOnly<'a>
impl<'a> Unpin for StopOnly<'a>
impl<'a> UnsafeUnpin for StopOnly<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more