Skip to main content

Crate cps_try

Crate cps_try 

Source
Expand description

A stable implementation of Rust’s Try and FromResidual.

This crate provides the trait machinery necessary to desugar the ? operator on stable Rust across Result, Option, ControlFlow, Poll, and layered types (e.g. Poll<Result<T, E>>, Poll<Option<Result<T, E>>>).

§The ? Desugaring Pattern

match cps_try::branch(expr) {
    std::ops::ControlFlow::Continue(val) => val,
    std::ops::ControlFlow::Break(residual) => return cps_try::from_residual(residual),
};

Because return from_residual(residual) is evaluated in return position, Rust’s standard type inference resolves the target return type automatically without requiring any explicit type annotations.

Macros§

try_op
Desugars the ? operator on stable Rust.

Structs§

ControlFlowResidual
The residual type representing an early break for ControlFlow.
OptionResidual
The residual type representing a None value for Option.
ResultResidual
The residual type representing a failed Result.

Traits§

FromResidual
Constructing a return type from an early-exit residual.
Try
Splitting an expression into a success value or an early-exit residual.

Functions§

branch
Branch a Try expression into ControlFlow.
from_residual
Convert an early-exit residual into the target return type.