37 lines
853 B
Rust
37 lines
853 B
Rust
use err_derive::Error;
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum TestError {
|
|
#[error(display = "invalid attribute (expected: {:?}, got: {:?})", expected, found)]
|
|
InvalidAttribute {
|
|
expected: String,
|
|
found: String,
|
|
},
|
|
#[error(display = "missing attribute: {:?}", _0)]
|
|
MissingAttribute(String),
|
|
}
|
|
|
|
|
|
fn main() {
|
|
println!("-----Error 0-----");
|
|
if let Err(e) = test_err_0() {
|
|
println!("{:?}", e);
|
|
println!("{}", e);
|
|
}
|
|
println!("-----Error 1-----");
|
|
if let Err(e) = test_err_1() {
|
|
println!("{:?}", e);
|
|
println!("{}", e);
|
|
}
|
|
}
|
|
|
|
fn test_err_0() -> Result<(), TestError> {
|
|
Err(TestError::MissingAttribute("test".into()))
|
|
}
|
|
|
|
fn test_err_1() -> Result<(), TestError> {
|
|
Err(TestError::InvalidAttribute {
|
|
expected: "aaa".into(),
|
|
found: "bbbb".into(),
|
|
})
|
|
} |