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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use bitflags::bitflags;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
bitflags! {
#[derive(Encode, Decode, MaxEncodedLen, scale_info::TypeInfo)]
pub struct FragmentPerms: u8 {
const NONE = 0;
const EDIT = 1;
const COPY = 2;
const TRANSFER = 4;
const ALL = Self::EDIT.bits | Self::COPY.bits | Self::TRANSFER.bits;
}
}
#[cfg(test)]
mod tests {
use super::*;
struct TestStruct {
pub _name: String,
pub permissions: FragmentPerms,
}
#[test]
fn t1() {
let test_struct = TestStruct {
_name: "test".to_string(),
permissions: FragmentPerms::NONE,
};
assert_eq!(test_struct.permissions.bits, 0);
}
#[test]
fn t2() {
let test_struct = TestStruct {
_name: "test".to_string(),
permissions: FragmentPerms::EDIT,
};
assert_eq!(test_struct.permissions.bits, 1);
}
#[test]
fn t3() {
let test_struct = TestStruct {
_name: "test".to_string(),
permissions: FragmentPerms::COPY,
};
assert_eq!(test_struct.permissions.bits, 2);
}
#[test]
fn t4() {
let test_struct = TestStruct {
_name: "test".to_string(),
permissions: FragmentPerms::TRANSFER,
};
assert_eq!(test_struct.permissions.bits, 4);
}
#[test]
fn t5() {
let test_struct = TestStruct {
_name: "test".to_string(),
permissions: FragmentPerms::ALL,
};
assert_eq!(test_struct.permissions.bits, 7);
}
}