Skip to main content

StopOnly

Struct StopOnly 

Source
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 StopOnly<'static>

Source

pub fn new(stop: impl Stop + 'static) -> Self

Own stop; the pulse and its shared views can outlive the caller.

Source§

impl<'a> StopOnly<'a>

Source

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 Debug for StopOnly<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Pulse for StopOnly<'_>

Source§

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>

Split this phase into weighted children, in declared order. Read more
Source§

fn share(&self) -> Result<SharedPulse, PlanError>

Share all pulse capabilities with owned work, but never completion rights. Read more
Source§

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.
Source§

fn start(&self) -> Result<(), PlanError>

Mark this phase running, without counting or ending planning. Implementations without lifecycle observations may ignore this.
Source§

impl Report for StopOnly<'_>

Source§

fn advance(&self, _: u64)

Add completed finished units.
Source§

fn may_report(&self) -> bool

Whether reports have any effect. Read more
Source§

impl Stop for StopOnly<'_>

Source§

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

Check if the operation should stop. Read more
Source§

fn may_stop(&self) -> bool

Returns true if this stop can ever signal a stop. Read more
Source§

fn should_stop(&self) -> bool

Returns true if the operation should stop. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

fn step(&self, completed: u64) -> Result<(), StopReason>

Count completed finished units, then check for cancellation. Read more
Source§

fn live(&self) -> Option<&Self>

The live pulse: this value, or None when it can neither stop nor report. Read more
Source§

fn split_array<const N: usize>( &self, execution: Execution, parts: [PhaseSpec<'_>; N], ) -> Result<[Child<'_>; N], PlanError>
where Self: Pulse,

Pulse::split into exactly N children, returned as an array. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.