blob: 0424af5fec1aa1d7d4969f2b8b7598965a1581d3 (
plain)
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
|
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
bitflags! {
#[derive(Serialize, Deserialize)]
struct Flags: u32 {
const A = 1;
const B = 2;
const C = 4;
const D = 8;
}
}
#[test]
fn serialize() {
let flags = Flags::A | Flags::B;
let serialized = serde_json::to_string(&flags).unwrap();
assert_eq!(serialized, r#"{"bits":3}"#);
}
#[test]
fn deserialize() {
let deserialized: Flags = serde_json::from_str(r#"{"bits":12}"#).unwrap();
let expected = Flags::C | Flags::D;
assert_eq!(deserialized.bits, expected.bits);
}
|