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§
Sourcefn context(self, field: &'static str) -> Result<T, ConversionError>
fn context(self, field: &'static str) -> Result<T, ConversionError>
Add field context to the error, wrapping it in a ConversionError if needed.