pub trait ErrorWrap<T, E>: Sealedwhere
    E: Send + Sync + 'static,
{ fn wrap<C>(self, context: C) -> Result<T, Error>
    where
        C: Display + Send + Sync + 'static
; fn wrap_with<C, F>(self, f: F) -> Result<T, Error>
    where
        C: Display + Send + Sync + 'static,
        F: FnOnce() -> C
; fn add_help(self, help: &'static str) -> Result<T, Error>; fn add_help_with<C, F>(self, f: F) -> Result<T, Error>
    where
        C: Display + Send + Sync + 'static,
        F: FnOnce() -> C
; }
Expand description

Provides wrap, wrap_help and wrap_help_owned methods for Result.

This trait is sealed and cannot be implemented for types outside of narrate.

Example

use narrate::{ErrorWrap, Result};
use std::fs;
use std::path::PathBuf;

pub struct ImportantThing {
    path: PathBuf,
}

impl ImportantThing {
    pub fn detach(&mut self) -> Result<()> {...}
}

pub fn do_it(mut it: ImportantThing) -> Result<Vec<u8>> {
    it.detach().wrap("Failed to detach the important thing")?;

    let path = &it.path;
    let content = fs::read(path)
        .wrap_with(|| format!("Failed to read instrs from {}", path.display()))?;

    Ok(content)
}

Required Methods

Wrap an error value with additional context

Wrap an error value with additional context that is evaluated lazily only once an error does occur.

Lazily evaluated error wrapper, with an additional static help message

Implementations on Foreign Types

Implementors