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
pub enum Flags {
None = 0,
Compressed = 1,
}
pub fn is_compressed(flags: u8) -> bool {
(flags & Flags::Compressed as u8) != 0
}
pub fn make_flags(compressed: bool) -> u8 {
let flag = if compressed {
Flags::Compressed
} else {
Flags::None
};
flag as u8
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_is_compressed() {
assert!(is_compressed(1))
}
#[test]
fn it_is_not_compressed() {
assert!(!is_compressed(0))
}
#[test]
fn it_is_compressed_and_other_flag() {
assert!(is_compressed(3))
}
#[test]
fn it_makes_flags_compressed() {
let flags = make_flags(true);
assert!(is_compressed(flags))
}
#[test]
fn it_makes_flags_not_compressed() {
let flags = make_flags(false);
assert!(!is_compressed(flags))
}
}