Skip to main content

Stage

Struct Stage 

Source
pub struct Stage<'s, 'p> { /* private fields */ }
Expand description

One active sequential stage, borrowing its plan until result handoff.

Pass &stage as the operation’s Pulse, then use crate::ResultExt::finish_phase or Complete::complete before ?. Completion consumes the handle and updates its plan. Dropping it without completion records Outcome::Abandoned and resolves pending work as Outcome::NotRun. Shared views have no completion rights.

A second stage cannot begin while the first is live:

ⓘ
use how_far::{prelude::*, NoPulse, PhaseSpec, Stages, Total};
let (mut stages, [a, b]) = Stages::define(&NoPulse, [
    PhaseSpec::new("a", 1, Total::Unknown),
    PhaseSpec::new("b", 1, Total::Unknown),
]);
let first = stages.begin(a);
let second = stages.begin(b);
first.complete(Ok::<_, how_far::StopReason>(())).unwrap();

Implementations§

Source§

impl Stage<'_, '_>

Source

pub fn fork<const N: usize>(&self, parts: [PhaseSpec<'_>; N]) -> [Child<'_>; N]

Start independently owned branches within this stage.

This declares Execution::ForkJoin and starts each branch; it does not schedule work. Move the handles into scoped threads, Rayon work, or borrowed async futures. Each branch can use different data and return a different type, or declare a nested Stages sequence.

Hand each result to its branch, join all workers, then hand the combined result to this stage. A failed branch does not automatically cancel its siblings. Every returned branch is active: dropping one unfinished records Outcome::Abandoned, not optional skipped work. Rejected plans retain cancellation in every branch and record an issue.

The parent cannot be completed while a branch still borrows it:

ⓘ
use how_far::{prelude::*, NoPulse, PhaseSpec, Stages, Total, Outcome};
let (mut stages, [work]) = Stages::define(&NoPulse, [
    PhaseSpec::new("work", 1, Total::Unknown),
]);
let work = stages.begin(work);
let [branch] = work.fork([PhaseSpec::new("branch", 1, Total::Unknown)]);
work.complete_as(Outcome::Succeeded);
branch.complete_as(Outcome::Succeeded);

Trait Implementations§

Source§

impl Complete for Stage<'_, '_>

Source§

fn complete_as(self, outcome: Outcome)

Record an explicitly chosen outcome, resolving unfinished observations. Join workers before calling this. Started but uncompleted children are abandoned; untouched children are skipped on success, not run on error.
Source§

fn complete<T, E>(self, result: Result<T, E>) -> Result<T, E>
where E: AsStopReason,

Classify the error with AsStopReason, record completion, and return the original result. Read more
Source§

fn complete_classified<T, E>( self, result: Result<T, E>, is_stop: impl FnOnce(&E) -> bool, ) -> Result<T, E>

Complete with an explicit classifier, for a foreign error type that Rust’s orphan rules keep from implementing AsStopReason.
Source§

fn complete_with<T, E>( self, body: impl FnOnce(&mut Self) -> Result<T, E>, ) -> Result<T, E>
where E: AsStopReason,

Run a multi-step body with this owner, then complete the owner with the body’s result and return that result unchanged. Read more
Source§

fn complete_with_classified<T, E>( self, is_stop: impl FnOnce(&E) -> bool, body: impl FnOnce(&mut Self) -> Result<T, E>, ) -> Result<T, E>

complete_with with an explicit classifier, for a foreign error type that cannot implement AsStopReason, such as an error wrapped with its source location.
Source§

impl Debug for Stage<'_, '_>

Source§

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

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

impl Drop for Stage<'_, '_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Pulse for Stage<'_, '_>

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 split( &self, execution: Execution, parts: &[PhaseSpec<'_>], ) -> Result<Vec<Child<'_>>, PlanError>

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

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

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

fn set_total(&self, total: Total) -> Result<(), PlanError>

Revise a leaf’s denominator without changing completed units or weights. Unsupported implementations return an error instead of losing the update.
Source§

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

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

impl Report for Stage<'_, '_>

Source§

fn advance(&self, completed: u64)

Add completed finished units.
Source§

fn may_report(&self) -> bool

Whether reports have any effect. Read more
Source§

impl Stop for Stage<'_, '_>

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<'s, 'p> !RefUnwindSafe for Stage<'s, 'p>

§

impl<'s, 'p> !UnwindSafe for Stage<'s, 'p>

§

impl<'s, 'p> Freeze for Stage<'s, 'p>

§

impl<'s, 'p> Send for Stage<'s, 'p>

§

impl<'s, 'p> Sync for Stage<'s, 'p>

§

impl<'s, 'p> Unpin for Stage<'s, 'p>

§

impl<'s, 'p> UnsafeUnpin for Stage<'s, 'p>

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.