use snafu::prelude::*; #[derive(Debug, Snafu)] enum Error { Leaf { name: String, }, BoxedSelf { #[snafu(source(from(Error, Box::new)))] source: Box, }, BoxedPublic { #[snafu(source(from(ApiError, Box::new)))] source: Box, }, } #[derive(Debug, Snafu)] #[snafu(source(from(Error, Box::new)))] struct ApiError(Box); type Result = std::result::Result; fn lookup() -> Result<()> { LeafSnafu { name: "foo" }.fail() } fn add() -> Result<()> { lookup().context(BoxedSelfSnafu) } fn public() -> Result<(), ApiError> { add()?; Ok(()) } fn re_private() -> Result<()> { public().context(BoxedPublicSnafu) } #[test] fn implements_error() { fn check() {} check::(); re_private().unwrap_err(); }