use snafu::{prelude::*, Backtrace}; use std::collections::HashMap; #[derive(Debug, Snafu)] enum Error { #[snafu(display("The left-hand argument {id} was missing"))] LeftHandMissing { id: i32, backtrace: Backtrace }, #[snafu(display("The right-hand argument {id} was missing"))] RightHandMissing { id: i32, backtrace: Backtrace }, } type Result = std::result::Result; fn example(values: &HashMap, left: i32, right: i32) -> Result { let l = values .get(&left) .context(LeftHandMissingSnafu { id: left })?; let r = values .get(&right) .context(RightHandMissingSnafu { id: right })?; Ok(l + r) } #[test] fn implements_error() { fn check() {} check::(); example(&Default::default(), 1, 2).unwrap_err(); }