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>whereE: Into<anyhow::Error>– wraps the error with context and converts it toControlFlow::Err.Option<T>– producesControlFlow::ErrwhenNone.
§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§
Sourcefn context<C: Display + Send + Sync + 'static>(
self,
context: C,
) -> Result<T, ControlFlow>
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.
Sourcefn with_context<C, F>(self, f: F) -> Result<T, ControlFlow>
fn with_context<C, F>(self, f: F) -> Result<T, ControlFlow>
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".