1use bitflags::bitflags;
2use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
3
4bitflags! {
5 #[derive(Encode, Decode, MaxEncodedLen, scale_info::TypeInfo)]
7 pub struct FragmentPerms: u8 {
8 const NONE = 0;
9 const EDIT = 1;
10 const COPY = 2;
11 const TRANSFER = 4;
12 const ALL = Self::EDIT.bits | Self::COPY.bits | Self::TRANSFER.bits;
13 }
14}
15
16#[cfg(test)]
17mod tests {
18 use super::*;
19
20 struct TestStruct {
21 pub _name: String,
22 pub permissions: FragmentPerms,
23 }
24
25 #[test]
26 fn t1() {
27 let test_struct = TestStruct {
28 _name: "test".to_string(),
29 permissions: FragmentPerms::NONE,
30 };
31
32 assert_eq!(test_struct.permissions.bits, 0);
33 }
34
35 #[test]
36 fn t2() {
37 let test_struct = TestStruct {
38 _name: "test".to_string(),
39 permissions: FragmentPerms::EDIT,
40 };
41
42 assert_eq!(test_struct.permissions.bits, 1);
43 }
44
45 #[test]
46 fn t3() {
47 let test_struct = TestStruct {
48 _name: "test".to_string(),
49 permissions: FragmentPerms::COPY,
50 };
51
52 assert_eq!(test_struct.permissions.bits, 2);
53 }
54
55 #[test]
56 fn t4() {
57 let test_struct = TestStruct {
58 _name: "test".to_string(),
59 permissions: FragmentPerms::TRANSFER,
60 };
61
62 assert_eq!(test_struct.permissions.bits, 4);
63 }
64
65 #[test]
66 fn t5() {
67 let test_struct = TestStruct {
68 _name: "test".to_string(),
69 permissions: FragmentPerms::ALL,
70 };
71
72 assert_eq!(test_struct.permissions.bits, 7);
73 }
74}