@@ -34,10 +34,8 @@ mod status;
34
34
pub use status:: Status ;
35
35
pub use uguid:: { guid, Guid } ;
36
36
37
- #[ cfg( feature = "unstable" ) ]
38
- use core:: error:: Error ;
39
37
use core:: ffi:: c_void;
40
- use core:: fmt:: { self , Debug , Display , Formatter } ;
38
+ use core:: fmt:: { self , Debug , Formatter } ;
41
39
42
40
/// Handle to an event structure.
43
41
pub type Event = * mut c_void ;
@@ -68,26 +66,11 @@ pub type PhysicalAddress = u64;
68
66
/// of target platform.
69
67
pub type VirtualAddress = u64 ;
70
68
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
-
86
69
/// ABI-compatible UEFI boolean.
87
70
///
88
71
/// Opaque 1-byte value holding either `0` for FALSE or a `1` for TRUE. This
89
72
/// type can be converted from and to `bool` via corresponding [`From`]
90
- /// respectively [`TryFrom`] implementations.
73
+ /// implementations.
91
74
#[ derive( Copy , Clone , Debug , Default , PartialEq , Ord , PartialOrd , Eq , Hash ) ]
92
75
#[ repr( transparent) ]
93
76
pub struct Boolean ( pub u8 ) ;
@@ -109,14 +92,13 @@ impl From<bool> for Boolean {
109
92
}
110
93
}
111
94
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
116
99
match value. 0 {
117
- 0 => Ok ( false ) ,
118
- 1 => Ok ( true ) ,
119
- x => Err ( InvalidBooleanError ( x) ) ,
100
+ 0 => false ,
101
+ _ => true ,
120
102
}
121
103
}
122
104
}
@@ -205,15 +187,10 @@ mod tests {
205
187
assert_eq ! ( Boolean :: from( false ) . 0 , 0 ) ;
206
188
assert_eq ! ( Boolean :: TRUE . 0 , 1 ) ;
207
189
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 ) ;
218
195
}
219
196
}
0 commit comments