use snafu::prelude::*; #[derive(Debug, Snafu)] enum AlphaError { _AlphaDummy, } #[derive(Debug, Snafu)] enum BetaError { _BetaDummy, } #[derive(Debug, Snafu)] enum Error { #[snafu(context(false))] Alpha { source: AlphaError }, #[snafu(context(false))] Beta { source: BetaError }, } fn alpha() -> Result { Ok(1) } fn beta() -> Result { Ok(2) } fn example() -> Result { let a = alpha()?; let b = beta()?; Ok(a * 10 + b) } fn check() {} #[test] fn implements_error() { check::(); assert_eq!(12, example().unwrap()); } mod with_backtraces { use super::*; use snafu::Backtrace; #[derive(Debug, Snafu)] enum Error { #[snafu(context(false))] Alpha { source: AlphaError, backtrace: Backtrace, }, } #[test] fn implements_error() { check::(); } } mod with_bounds { use super::*; use std::fmt::{Debug, Display}; #[derive(Debug, Snafu)] enum GenericError { _Something { things: T, other: U }, } #[derive(Debug, Snafu)] enum Error where T: Debug + Display + Copy, { #[snafu(context(false))] Generic { source: GenericError }, } #[test] fn implements_error() { check::>(); } }