pub trait FailExt<T> {
// Required method
fn context<S: ToString>(self, msg: S) -> Result<T, Fail>;
}Expand description
A support trait for implementing rich error message.
This trait implemented for Option and Result.
You can
§Example
use std::fs::File;
use std::io::{BufRead, BufReader};
use tiny_fail::{Fail, FailExt};
fn foo() -> Result<(), Fail> {
let f = File::open("not_exists.txt").context("failed open not_exists.txt")?;
let r = BufReader::new(f);
for line in r.lines() {
let line = line.context("failed read line")?;
let num = line.parse::<f64>().context(format!("failed parse \"{}\" into floating number", line))?;
println!("{:.2}", num);
}
Ok(())
}Required Methods§
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.