1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#![cfg(feature="std")]
use snafu::prelude::*;
#[derive(Debug, Snafu)]
enum Error {
Leaf {
name: String,
},
BoxedSelf {
#[snafu(source(from(Error, Box::new)))]
source: Box<Error>,
},
BoxedPublic {
#[snafu(source(from(ApiError, Box::new)))]
source: Box<ApiError>,
},
}
#[derive(Debug, Snafu)]
#[snafu(source(from(Error, Box::new)))]
struct ApiError(Box<Error>);
type Result<T, E = Error> = std::result::Result<T, E>;
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<T: std::error::Error>() {}
check::<Error>();
re_private().unwrap_err();
}
|