#[macro_use] extern crate stacktrace; use std::fmt::Debug; #[derive(Debug)] struct ErrorX(String); #[derive(Debug)] struct ErrorY(ErrorX); #[derive(Debug)] struct ErrorZ(ErrorY); impl From for ErrorY { fn from(x: ErrorX) -> Self { ErrorY(x) } } impl From for ErrorZ { fn from(y: ErrorY) -> Self { ErrorZ(y) } } trace! { ErrorX => ErrorY, ErrorY => ErrorZ, } fn test1(n: usize) -> Result { if n >= 10 { return Err(ErrorX(format!("{} is too big!", n))) } Ok(format!("{} is small enough.", n)) } fn test2(n: usize) -> Result> { // uses the generated "From for Trace" let result = try!(test1(n)); println!("Test 2 got result {:?}", result); Ok(result) } fn test3(n: usize) -> Result> { // uses the generated "From> for Trace" let result = try!(test2(n)); println!("Test 3 got result {:?}", result); Ok(result) } fn main() { println!("Success:\n{:?}\n", test3(1)); println!("Failure:\n{:?}\n", test3(10)); }