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
#[derive(Debug, Fail, PartialEq)]
pub enum AttributeError {
#[fail(display = "Invalid format")]
InvalidFormat,
#[fail(display = "Invalid type")]
InvalidType,
#[fail(display = "Missing field {}", name)]
MissingField {
name: String,
},
}
#[cfg(test)]
mod tests {
use super::AttributeError;
#[test]
fn invalid_format_displays() {
assert_eq!(
"Invalid format",
format!("{}", AttributeError::InvalidFormat)
)
}
#[test]
fn invalid_type_displays() {
assert_eq!("Invalid type", format!("{}", AttributeError::InvalidType))
}
#[test]
fn missing_field_displays() {
assert_eq!(
"Missing field foo",
format!("{}", AttributeError::MissingField { name: "foo".into() })
)
}
}