@@ -7,66 +7,16 @@ const FIB_RULE_IIF_DETACHED: u32 = 0x00000008;
77const FIB_RULE_DEV_DETACHED : u32 = FIB_RULE_IIF_DETACHED ;
88const FIB_RULE_OIF_DETACHED : u32 = 0x00000010 ;
99
10- #[ derive( Clone , Eq , PartialEq , Debug , Copy ) ]
11- #[ non_exhaustive]
12- pub enum RuleFlag {
13- Permanent ,
14- Invert ,
15- Unresolved ,
16- IifDetached ,
17- DevDetached ,
18- OifDetached ,
19- Other ( u32 ) ,
20- }
21-
22- const ALL_RULE_FLAGS : [ RuleFlag ; 5 ] = [
23- RuleFlag :: Permanent ,
24- RuleFlag :: Invert ,
25- RuleFlag :: Unresolved ,
26- RuleFlag :: IifDetached ,
27- RuleFlag :: OifDetached ,
28- ] ;
29-
30- impl From < RuleFlag > for u32 {
31- fn from ( v : RuleFlag ) -> u32 {
32- match v {
33- RuleFlag :: Permanent => FIB_RULE_PERMANENT ,
34- RuleFlag :: Invert => FIB_RULE_INVERT ,
35- RuleFlag :: Unresolved => FIB_RULE_UNRESOLVED ,
36- RuleFlag :: IifDetached => FIB_RULE_IIF_DETACHED ,
37- RuleFlag :: DevDetached => FIB_RULE_DEV_DETACHED ,
38- RuleFlag :: OifDetached => FIB_RULE_OIF_DETACHED ,
39- RuleFlag :: Other ( i) => i,
40- }
41- }
42- }
43-
44- #[ derive( Clone , Eq , PartialEq , Debug , Default ) ]
45- pub ( crate ) struct VecRuleFlag ( pub ( crate ) Vec < RuleFlag > ) ;
46-
47- impl From < u32 > for VecRuleFlag {
48- fn from ( d : u32 ) -> Self {
49- let mut got: u32 = 0 ;
50- let mut ret = Vec :: new ( ) ;
51- for flag in ALL_RULE_FLAGS {
52- if ( d & ( u32:: from ( flag) ) ) > 0 {
53- ret. push ( flag) ;
54- got += u32:: from ( flag) ;
55- }
56- }
57- if got != d {
58- ret. push ( RuleFlag :: Other ( d - got) ) ;
59- }
60- Self ( ret)
61- }
62- }
63-
64- impl From < & VecRuleFlag > for u32 {
65- fn from ( v : & VecRuleFlag ) -> u32 {
66- let mut d: u32 = 0 ;
67- for flag in & v. 0 {
68- d += u32:: from ( * flag) ;
69- }
70- d
10+ bitflags ! {
11+ #[ derive( Clone , Eq , PartialEq , Debug , Copy , Default ) ]
12+ #[ non_exhaustive]
13+ pub struct RuleFlags : u32 {
14+ const Permanent = FIB_RULE_PERMANENT ;
15+ const Invert = FIB_RULE_INVERT ;
16+ const Unresolved = FIB_RULE_UNRESOLVED ;
17+ const IifDetached = FIB_RULE_IIF_DETACHED ;
18+ const DevDetached = FIB_RULE_DEV_DETACHED ;
19+ const OifDetached = FIB_RULE_OIF_DETACHED ;
20+ const _ = !0 ;
7121 }
7222}
0 commit comments