#[macro_use] extern crate justerror; #[Error(desc = "This is my error.")] enum MyEnumError { Foo, #[error(desc = "This is bar.")] Bar { a: &'static str, b: i32, }, Baz(#[fmt(debug)] Vec<&'static str>, u32), Woa(#[from] MyEnumError2), } #[Error] enum MyEnumError2 { Hey { a: &'static str, b: i32 }, } #[Error] struct MyStructError { #[fmt(debug)] foo: &'static str, bar: i32, } fn main() { let enum_foo_error = MyEnumError::Foo; let enum_bar_error = MyEnumError::Bar { a: "BAR\nBAR", b: 42, }; let enum_baz_error = MyEnumError::Baz(vec!["One", "Two"], 7); let struct_error = MyStructError { foo: "FOO", bar: 42, }; let x: MyEnumError = MyEnumError2::Hey { a: "qwe", b: 42 }.into(); println!("{}", enum_foo_error); println!(""); println!("{}", enum_bar_error); println!(""); println!("{}", enum_baz_error); println!(""); println!("{}", struct_error); println!(""); println!("{}", x); }