@@ -34,10 +34,8 @@ mod status;
3434pub  use  status:: Status ; 
3535pub  use  uguid:: { guid,  Guid } ; 
3636
37- #[ cfg( feature = "unstable" ) ]  
38- use  core:: error:: Error ; 
3937use  core:: ffi:: c_void; 
40- use  core:: fmt:: { self ,  Debug ,  Display ,   Formatter } ; 
38+ use  core:: fmt:: { self ,  Debug ,  Formatter } ; 
4139
4240/// Handle to an event structure. 
4341pub  type  Event  = * mut  c_void ; 
@@ -68,26 +66,11 @@ pub type PhysicalAddress = u64;
6866/// of target platform. 
6967pub  type  VirtualAddress  = u64 ; 
7068
71- /// The provided [`Boolean`] can't be converted to [`bool`] as it is neither 
72- /// `0` nor `1`. 
73- #[ derive( Debug ,  Copy ,  Clone ,  PartialEq ,  Ord ,  PartialOrd ,  Eq ) ]  
74- #[ repr( transparent) ]  
75- pub  struct  InvalidBooleanError ( pub  u8 ) ; 
76- 
77- impl  Display  for  InvalidBooleanError  { 
78-     fn  fmt ( & self ,  f :  & mut  Formatter < ' _ > )  -> fmt:: Result  { 
79-         Debug :: fmt ( self ,  f) 
80-     } 
81- } 
82- 
83- #[ cfg( feature = "unstable" ) ]  
84- impl  Error  for  InvalidBooleanError  { } 
85- 
8669/// ABI-compatible UEFI boolean. 
8770/// 
8871/// Opaque 1-byte value holding either `0` for FALSE or a `1` for TRUE. This 
8972/// type can be converted from and to `bool` via corresponding [`From`] 
90- /// respectively [`TryFrom`]  implementations. 
73+ /// implementations. 
9174#[ derive( Copy ,  Clone ,  Debug ,  Default ,  PartialEq ,  Ord ,  PartialOrd ,  Eq ,  Hash ) ]  
9275#[ repr( transparent) ]  
9376pub  struct  Boolean ( pub  u8 ) ; 
@@ -109,14 +92,13 @@ impl From<bool> for Boolean {
10992    } 
11093} 
11194
112- impl  TryFrom < Boolean >  for  bool  { 
113-     type   Error  =  InvalidBooleanError ; 
114- 
115-     fn   try_from ( value :   Boolean )  ->  Result < Self ,   Self :: Error >   { 
95+ impl  From < Boolean >  for  bool  { 
96+     # [ allow ( clippy :: match_like_matches_macro ) ] 
97+      fn   from ( value :   Boolean )  ->  Self   { 
98+          // We handle it as in C: Any bit-pattern != 0 equals true 
11699        match  value. 0  { 
117-             0  => Ok ( false ) , 
118-             1  => Ok ( true ) , 
119-             x => Err ( InvalidBooleanError ( x) ) , 
100+             0  => false , 
101+             _ => true , 
120102        } 
121103    } 
122104} 
@@ -205,15 +187,10 @@ mod tests {
205187        assert_eq ! ( Boolean :: from( false ) . 0 ,  0 ) ; 
206188        assert_eq ! ( Boolean :: TRUE . 0 ,  1 ) ; 
207189        assert_eq ! ( Boolean :: FALSE . 0 ,  0 ) ; 
208-         assert_eq ! ( bool :: try_from( Boolean ( 0b0 ) ) ,  Ok ( false ) ) ; 
209-         assert_eq ! ( bool :: try_from( Boolean ( 0b1 ) ) ,  Ok ( true ) ) ; 
210-         assert_eq ! ( 
211-             bool :: try_from( Boolean ( 0b11 ) ) , 
212-             Err ( InvalidBooleanError ( 0b11 ) ) 
213-         ) ; 
214-         assert_eq ! ( 
215-             bool :: try_from( Boolean ( 0b10 ) ) , 
216-             Err ( InvalidBooleanError ( 0b10 ) ) 
217-         ) ; 
190+         assert_eq ! ( bool :: from( Boolean ( 0b0 ) ) ,  false ) ; 
191+         assert_eq ! ( bool :: from( Boolean ( 0b1 ) ) ,  true ) ; 
192+         // We do it a C: Every bit pattern not 0 is equal to true 
193+         assert_eq ! ( bool :: from( Boolean ( 0b11111110 ) ) ,  true ) ; 
194+         assert_eq ! ( bool :: from( Boolean ( 0b11111111 ) ) ,  true ) ; 
218195    } 
219196} 
0 commit comments