Skip to main content

ControlFlowExt

Trait ControlFlowExt 

Source
pub trait ControlFlowExt<T> {
    // Required methods
    fn context<C: Display + Send + Sync + 'static>(
        self,
        context: C,
    ) -> Result<T, ControlFlow>;
    fn with_context<C, F>(self, f: F) -> Result<T, ControlFlow>
       where C: Display + Send + Sync + 'static,
             F: FnOnce() -> C;
}
Expand description

Extension trait for wrapping errors with context and converting them into ControlFlow.

Modelled on anyhow::Context, this provides .context() and .with_context() methods that map any compatible error into ControlFlow::Err with the given message.

§Implemented for

  • Result<T, E> where E: Into<anyhow::Error> – wraps the error with context and converts it to ControlFlow::Err.
  • Option<T> – produces ControlFlow::Err when None.

§Examples

ⓘ
use crate::expr::ControlFlowExt;

// Convert a Result<T, E> into FlowResult<T> with context:
let key = encode_key(data).context("Failed to encode scan key")?;

// Unwrap an Option<T> into FlowResult<T> with context:
let table = opt_table.context("Referencing table is required")?;

Required Methods§

Source

fn context<C: Display + Send + Sync + 'static>( self, context: C, ) -> Result<T, ControlFlow>

Wrap the error value with additional context, converting it into a ControlFlow::Err.

Source

fn with_context<C, F>(self, f: F) -> Result<T, ControlFlow>
where C: Display + Send + Sync + 'static, F: FnOnce() -> C,

Wrap the error value with lazily-evaluated context, converting it into a ControlFlow::Err.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, E: Into<Error>> ControlFlowExt<T> for Result<T, E>

Source§

fn context<C: Display + Send + Sync + 'static>( self, context: C, ) -> Result<T, ControlFlow>

Source§

fn with_context<C, F>(self, f: F) -> Result<T, ControlFlow>
where C: Display + Send + Sync + 'static, F: FnOnce() -> C,

Source§

impl<T> ControlFlowExt<T> for Option<T>

Source§

fn context<C: Display + Send + Sync + 'static>( self, context: C, ) -> Result<T, ControlFlow>

Source§

fn with_context<C, F>(self, f: F) -> Result<T, ControlFlow>
where C: Display + Send + Sync + 'static, F: FnOnce() -> C,

Implementors§