Skip to main content

StringResultExt

Trait StringResultExt 

Source
pub trait StringResultExt<T> {
    // Required method
    fn with_context(self, context: &str) -> Result<T, String>;
}
Expand description

Extension trait that adds .with_context() to Result<T, String>.

Many stdlib module functions return Result<T, String>. This trait lets callers wrap a bare string error with function-name context:

serde_json::from_str(data)
    .map_err(|e| e.to_string())
    .with_context("json.parse")?;
// error becomes: "json.parse(): <original message>"

Required Methods§

Source

fn with_context(self, context: &str) -> Result<T, String>

Wrap the error string with "context(): original_error" on failure.

Implementations on Foreign Types§

Source§

impl<T> StringResultExt<T> for Result<T, String>

Source§

fn with_context(self, context: &str) -> Result<T, String>

Implementors§