@@ -15,17 +15,55 @@ 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( Clone , Copy ) ]
19+ pub ( crate ) struct Flags ( u8 ) ;
20+
21+ impl Flags {
22+ pub const VALUE_ALLOCATED : Flags = Flags ( 0b0000_0001 ) ;
23+ pub const VALUE_INITIALIZED : Flags = Flags ( 0b0000_0010 ) ;
24+ pub const CHILD_ALLOCATED : Flags = Flags ( 0b0000_0100 ) ;
25+ pub const CHILD_INITIALIZED : Flags = Flags ( 0b0000_1000 ) ;
26+ pub const SIBLING_ALLOCATED : Flags = Flags ( 0b0001_0000 ) ;
27+ pub const SIBLING_INITIALIZED : Flags = Flags ( 0b0010_0000 ) ;
28+
29+ pub const fn empty ( ) -> Self {
30+ Flags ( 0 )
31+ }
32+
33+ pub const fn from_bits_truncate ( bits : u8 ) -> Self {
34+ Flags ( bits)
35+ }
36+
37+ pub const fn bits ( self ) -> u8 {
38+ self . 0
39+ }
40+
41+ pub const fn contains ( self , other : Flags ) -> bool {
42+ ( self . 0 & other. 0 ) == other. 0
43+ }
44+
45+ pub const fn intersects ( self , other : Flags ) -> bool {
46+ ( self . 0 & other. 0 ) != 0
47+ }
48+
49+ pub fn insert ( & mut self , other : Flags ) {
50+ self . 0 |= other. 0 ;
51+ }
52+
53+ pub fn set ( & mut self , other : Flags , value : bool ) {
54+ if value {
55+ self . 0 |= other. 0 ;
56+ } else {
57+ self . 0 &= !other. 0 ;
58+ }
59+ }
60+ }
2361
24- const CHILD_ALLOCATED = 0b0000_0100 ;
25- const CHILD_INITIALIZED = 0b0000_1000 ;
62+ impl core :: ops :: BitOr for Flags {
63+ type Output = Self ;
2664
27- const SIBLING_ALLOCATED = 0b0001_0000 ;
28- const SIBLING_INITIALIZED = 0b0010_0000 ;
65+ fn bitor ( self , other : Self ) -> Self {
66+ Flags ( self . 0 | other . 0 )
2967 }
3068}
3169
0 commit comments