158
158
target_arch = "wasm32" ,
159
159
) ) ]
160
160
pub mod unix;
161
+ use std:: ops:: Deref ;
161
162
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
162
163
use std:: time:: Duration ;
163
164
@@ -243,12 +244,50 @@ impl std::error::Error for Error {}
243
244
/// assert_eq!(raw_value, 0);
244
245
/// ```
245
246
#[ derive( Copy , Clone , Debug , Default , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
246
- pub struct ThreadPriorityValue ( u8 ) ;
247
+ pub struct ThreadPriorityValue ( pub ( crate ) u8 ) ;
247
248
impl ThreadPriorityValue {
248
249
/// The maximum value for a thread priority.
249
- pub const MAX : u8 = if cfg ! ( target_os = "vxworks" ) { 255 } else { 99 } ;
250
+ pub const MAX : Self = Self ( if cfg ! ( target_os = "vxworks" ) { 255 } else { 99 } ) ;
250
251
/// The minimum value for a thread priority.
251
- pub const MIN : u8 = 0 ;
252
+ pub const MIN : Self = Self ( 0 ) ;
253
+ }
254
+
255
+ impl Deref for ThreadPriorityValue {
256
+ type Target = u8 ;
257
+
258
+ fn deref ( & self ) -> & Self :: Target {
259
+ & self . 0
260
+ }
261
+ }
262
+
263
+ impl PartialOrd < u8 > for ThreadPriorityValue {
264
+ fn partial_cmp ( & self , other : & u8 ) -> Option < std:: cmp:: Ordering > {
265
+ self . 0 . partial_cmp ( other)
266
+ }
267
+ }
268
+
269
+ impl PartialOrd < ThreadPriorityValue > for u8 {
270
+ fn partial_cmp ( & self , other : & ThreadPriorityValue ) -> Option < std:: cmp:: Ordering > {
271
+ self . partial_cmp ( & other. 0 )
272
+ }
273
+ }
274
+
275
+ impl PartialEq < u8 > for ThreadPriorityValue {
276
+ fn eq ( & self , other : & u8 ) -> bool {
277
+ self . 0 == * other
278
+ }
279
+ }
280
+
281
+ impl PartialEq < ThreadPriorityValue > for u8 {
282
+ fn eq ( & self , other : & ThreadPriorityValue ) -> bool {
283
+ * self == other. 0
284
+ }
285
+ }
286
+
287
+ impl std:: fmt:: Display for ThreadPriorityValue {
288
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
289
+ write ! ( f, "{}" , self . 0 )
290
+ }
252
291
}
253
292
254
293
impl std:: convert:: TryFrom < u8 > for ThreadPriorityValue {
@@ -267,12 +306,9 @@ impl std::convert::TryFrom<u8> for ThreadPriorityValue {
267
306
}
268
307
}
269
308
270
- // The From<u8> is unsafe, so there is a TryFrom instead.
271
- // For this reason we silent the warning from clippy.
272
- #[ allow( clippy:: from_over_into) ]
273
- impl std:: convert:: Into < u8 > for ThreadPriorityValue {
274
- fn into ( self ) -> u8 {
275
- self . 0
309
+ impl From < ThreadPriorityValue > for u8 {
310
+ fn from ( value : ThreadPriorityValue ) -> Self {
311
+ value. 0
276
312
}
277
313
}
278
314
0 commit comments