Skip to main content

Context

Trait Context 

Source
pub trait Context<T, E: StdError> {
    // Required method
    fn context(self, context: &str, hint: Option<&str>) -> Result<T>;
}
Expand description

Trait for adding context and an optional hint to errors.

§example:

use idc::*;  
use std::fs;  
fn main() -> Result<()> {  
    let foo = fs::read_to_string("foo").context("failed to read foo.", "maybe it doesn't exist?".into())?;  
    println!("{}", foo);  
    Ok(())  
}

Required Methods§

Source

fn context(self, context: &str, hint: Option<&str>) -> Result<T>

Function for adding context and an option hint to an error.

See Context for an exmaple.

Implementations on Foreign Types§

Source§

impl<T, E: StdError> Context<T, E> for Result<T, E>

Source§

fn context(self, context: &str, hint: Option<&str>) -> Result<T>

Implementors§