Context

Trait Context 

Source
pub trait Context<T> {
    // Required methods
    fn context(self, msg: impl Into<String>) -> Result<T, Error>;
    fn with_context<F, S>(self, cb: F) -> Result<T, Error>
       where F: Fn() -> S,
             S: Into<String>;
}
Expand description

Helper trait for creating Error instances.

This trait is inspired by anyhow::Context.

§Examples

use genpdfi_extended::error::{Context as _, Error};
use std::io;
let res: Result<(), io::Error> = Err(io::Error::new(io::ErrorKind::Other, "boom"));
let mapped = res.context("wrapped");
assert!(mapped.is_err());

Required Methods§

Source

fn context(self, msg: impl Into<String>) -> Result<T, Error>

Maps the error to an Error instance with the given message.

Source

fn with_context<F, S>(self, cb: F) -> Result<T, Error>
where F: Fn() -> S, S: Into<String>,

Maps the error to an Error instance message produced by the given callback.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T, E: Into<ErrorKind>> Context<T> for Result<T, E>

Source§

fn context(self, msg: impl Into<String>) -> Result<T, Error>

Source§

fn with_context<F, S>(self, cb: F) -> Result<T, Error>
where F: Fn() -> S, S: Into<String>,

Implementors§