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
50
51
52
53
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum ContextType {
Content,
Social,
Product,
ExchangeSpecific(i32),
}
crate::impl_enum_serde!(
#[exchange(ident = ExchangeSpecific, greater = 500)]
ContextType {
Content = 1,
Social = 2,
Product = 3,
}
);
#[cfg(test)]
mod test {
use super::*;
#[test]
fn json() -> serde_json::Result<()> {
assert!(serde_json::from_str::<ContextType>("0").is_err());
assert!(serde_json::from_str::<ContextType>("500").is_err());
let json = "[1,2,3,501]";
let e1: Vec<ContextType> = serde_json::from_str(json)?;
assert_eq!(serde_json::to_string(&e1)?, json);
assert_eq!(
e1,
vec![
ContextType::Content,
ContextType::Social,
ContextType::Product,
ContextType::ExchangeSpecific(501),
]
);
Ok(())
}
}