Skip to main content

Stages

Struct Stages 

Source
pub struct Stages<'a> { /* private fields */ }
Expand description

Sequential work returning the library’s ordinary Result<T, E>.

Start with Stages::define: bind its reservations to variables, use Stages::begin to obtain each active handle, and call your operation with &stage. For repeated work over a runtime-sized list, Stages::new and Stages::begin_next provide the same handle and result handoff.

Implement AsStopReason for your error to recognize cancellation. From<StopReason> supports ? at checks; no planning-error conversion is required. For explicitly fallible planning use crate::TryStages.

Pass the final result to complete (or ResultExt::finish_phase) to resolve untouched stages. Use Stages::begin for direct function calls and hand each result to crate::ResultExt::finish_phase before applying ?. Drop alone records abandonment. Recovery belongs within the operation that owns a stage, using separate child owners for individual attempts.

Implementations§

Source§

impl<'a> Stages<'a>

Source

pub fn new(parent: &'a dyn Pulse, parts: &[PhaseSpec<'_>]) -> Self

Declare a runtime-sized sequence for Stages::begin_next or Stages::run.

For a fixed set of distinct operations, Stages::define also gives you reservations to bind to variables. Rejected observations retain cancellation through fallback children and cannot fail the work.

Source

pub fn define<const N: usize>( parent: &'a dyn Pulse, parts: [PhaseSpec<'_>; N], ) -> (Self, [StageKey; N])

Declare a sequence and bind its reservations to variables.

Destructure the returned array, then pass each key to Stages::begin in declaration order. Keys belong to this particular plan, even when another plan has identical specifications. Moving the plan is allowed. Dropping a key does not abandon its pending stage: the plan retains completion authority until the stage begins or the plan completes.

Labels are for observers only; beginning a stage never compares strings. One shared identity allocation belongs to each nonempty definition.

Source

pub fn begin(&mut self, key: StageKey) -> Stage<'_, 'a>

Begin the next stage using its reservation from Stages::define.

Hand the operation’s result to crate::ResultExt::finish_phase before applying ?. Failed or cancelled handoffs immediately mark remaining stages Outcome::NotRun. Complete the plan with its final result to resolve untouched optional work.

A key from another plan, out of order, or already used records PlanError::StageMismatch and returns a cancellation-only stage without consuming the next declaration. After failure or exhaustion, work also retains cancellation and the protocol issue is recorded.

Only one active stage can borrow the plan. Join workers before handing over that stage’s result. Dropping it unfinished records abandonment and prevents the remaining sequence from earning progress.

Source

pub fn begin_next(&mut self) -> Stage<'_, 'a>

Begin the next stage in a runtime-sized sequence.

Use with Stages::new when a loop repeats the same operation over a slice. The handle and result handoff are the same as Stages::begin, but no key is checked. Exhaustion records PlanError::NoMoreStages and returns a cancellation-only stage.

Source

pub fn run<T, E>( &mut self, work: impl FnOnce(&dyn Pulse) -> Result<T, E>, ) -> Result<T, E>
where E: AsStopReason,

Run the next stage, preserving the original result and error identity. After a stage error, later declared stages become NotRun. Calling again is diagnosed and runs against a cancellation-only view of the parent.

Source

pub fn run_classified<T, E>( &mut self, is_stop: impl FnOnce(&E) -> bool, work: impl FnOnce(&dyn Pulse) -> Result<T, E>, ) -> Result<T, E>

Run with an explicit classifier for foreign error wrappers or a local classification policy, returning the work’s original Result unchanged.

Source

pub fn skip(&mut self)

Explicitly mark the next phase unnecessary, making that decision visible now.

Trait Implementations§

Source§

impl Complete for Stages<'_>

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.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Stages<'a>

§

impl<'a> !UnwindSafe for Stages<'a>

§

impl<'a> Freeze for Stages<'a>

§

impl<'a> Send for Stages<'a>

§

impl<'a> Sync for Stages<'a>

§

impl<'a> Unpin for Stages<'a>

§

impl<'a> UnsafeUnpin for Stages<'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, 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.