File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,26 @@ macro_rules! impl_numeric_integer {
60
60
} ;
61
61
}
62
62
63
+ macro_rules! impl_numeric_non_zero_unsigned {
64
+ ( $t: path) => {
65
+ impl Numeric for $t {
66
+ const INTEGRAL : bool = true ;
67
+ const MIN : Self = Self :: MIN ;
68
+ const MAX : Self = Self :: MAX ;
69
+
70
+ #[ inline( always) ]
71
+ fn to_f64( self ) -> f64 {
72
+ self . get( ) as f64
73
+ }
74
+
75
+ #[ inline( always) ]
76
+ fn from_f64( num: f64 ) -> Self {
77
+ Self :: new( num. round( ) . max( 1.0 ) as _) . unwrap_or( Self :: MIN )
78
+ }
79
+ }
80
+ } ;
81
+ }
82
+
63
83
impl_numeric_float ! ( f32 ) ;
64
84
impl_numeric_float ! ( f64 ) ;
65
85
impl_numeric_integer ! ( i8 ) ;
@@ -72,3 +92,9 @@ impl_numeric_integer!(i64);
72
92
impl_numeric_integer ! ( u64 ) ;
73
93
impl_numeric_integer ! ( isize ) ;
74
94
impl_numeric_integer ! ( usize ) ;
95
+ impl_numeric_non_zero_unsigned ! ( std:: num:: NonZeroU8 ) ;
96
+ impl_numeric_non_zero_unsigned ! ( std:: num:: NonZeroU16 ) ;
97
+ impl_numeric_non_zero_unsigned ! ( std:: num:: NonZeroU32 ) ;
98
+ impl_numeric_non_zero_unsigned ! ( std:: num:: NonZeroU64 ) ;
99
+ impl_numeric_non_zero_unsigned ! ( std:: num:: NonZeroU128 ) ;
100
+ impl_numeric_non_zero_unsigned ! ( std:: num:: NonZeroUsize ) ;
You can’t perform that action at this time.
0 commit comments