Skip to main content

ConversionResultExt

Trait ConversionResultExt 

Source
pub trait ConversionResultExt<T> {
    // Required method
    fn context(self, field: &'static str) -> Result<T, ConversionError>;
}
Expand description

Extension trait to ergonomically add field context to ConversionError results.

This makes it easy to inject field names into the error path at each ? site:

let account_root = value.account_root
    .ok_or(ConversionError::missing_field::<proto::BlockHeader>("account_root"))?
    .try_into()
    .context("account_root")?;

The context stacks automatically through nested conversions, producing error paths like "header.account_root: value is not in range 0..MODULUS".

Required Methods§

Source

fn context(self, field: &'static str) -> Result<T, ConversionError>

Add field context to the error, wrapping it in a ConversionError if needed.

Implementations on Foreign Types§

Source§

impl<T, E: Into<ConversionError>> ConversionResultExt<T> for Result<T, E>

Source§

fn context(self, field: &'static str) -> Result<T, ConversionError>

Implementors§