@@ -15,17 +15,57 @@ macro_rules! assert_some {
1515 } ;
1616}
1717
18- bitflags ! {
19- #[ derive( Clone , Copy ) ]
20- pub ( crate ) struct Flags : u8 {
21- const VALUE_ALLOCATED = 0b0000_0001 ;
22- const VALUE_INITIALIZED = 0b0000_0010 ;
18+ #[ derive( Debug , Clone , Copy ) ]
19+ pub ( crate ) struct Flags ( u8 ) ;
2320
24- const CHILD_ALLOCATED = 0b0000_0100 ;
25- const CHILD_INITIALIZED = 0b0000_1000 ;
21+ impl Flags {
22+ pub ( crate ) const VALUE_ALLOCATED : Flags = Flags ( 0b0000_0001 ) ;
23+ pub ( crate ) const VALUE_INITIALIZED : Flags = Flags ( 0b0000_0010 ) ;
24+ pub ( crate ) const CHILD_ALLOCATED : Flags = Flags ( 0b0000_0100 ) ;
25+ pub ( crate ) const CHILD_INITIALIZED : Flags = Flags ( 0b0000_1000 ) ;
26+ pub ( crate ) const SIBLING_ALLOCATED : Flags = Flags ( 0b0001_0000 ) ;
27+ pub ( crate ) const SIBLING_INITIALIZED : Flags = Flags ( 0b0010_0000 ) ;
2628
27- const SIBLING_ALLOCATED = 0b0001_0000 ;
28- const SIBLING_INITIALIZED = 0b0010_0000 ;
29+ const VALID_BITS_MASK : u8 = 0b0011_1111 ; // Mask of all valid flag bits.
30+
31+ const fn empty ( ) -> Self {
32+ Flags ( 0 )
33+ }
34+
35+ pub ( crate ) const fn from_bits_truncate ( bits : u8 ) -> Self {
36+ Flags ( bits & Self :: VALID_BITS_MASK )
37+ }
38+
39+ pub ( crate ) const fn bits ( self ) -> u8 {
40+ self . 0
41+ }
42+
43+ pub ( crate ) const fn contains ( self , other : Flags ) -> bool {
44+ ( self . 0 & other. 0 ) == other. 0
45+ }
46+
47+ const fn intersects ( self , other : Flags ) -> bool {
48+ ( self . 0 & other. 0 ) != 0
49+ }
50+
51+ fn insert ( & mut self , other : Flags ) {
52+ self . 0 |= other. 0 ;
53+ }
54+
55+ fn set ( & mut self , other : Flags , value : bool ) {
56+ if value {
57+ self . 0 |= other. 0 ;
58+ } else {
59+ self . 0 &= !other. 0 ;
60+ }
61+ }
62+ }
63+
64+ impl core:: ops:: BitOr for Flags {
65+ type Output = Self ;
66+
67+ fn bitor ( self , other : Self ) -> Self {
68+ Flags ( self . 0 | other. 0 )
2969 }
3070}
3171
0 commit comments