@@ -984,6 +984,30 @@ impl TryFrom<f64> for NotNan<f64> {
984
984
}
985
985
}
986
986
987
+ macro_rules! impl_from_int_primitive {
988
+ ( $primitive: ty, $inner: ty) => {
989
+ impl From <$primitive> for NotNan <$inner> {
990
+ fn from( source: $primitive) -> Self {
991
+ // the primitives with which this macro will be called cannot hold a value that
992
+ // f64::from would convert to NaN, so this does not hurt invariants
993
+ NotNan ( <$inner as From <$primitive>>:: from( source) )
994
+ }
995
+ }
996
+ } ;
997
+ }
998
+
999
+ impl_from_int_primitive ! ( i8 , f64 ) ;
1000
+ impl_from_int_primitive ! ( i16 , f64 ) ;
1001
+ impl_from_int_primitive ! ( i32 , f64 ) ;
1002
+ impl_from_int_primitive ! ( u8 , f64 ) ;
1003
+ impl_from_int_primitive ! ( u16 , f64 ) ;
1004
+ impl_from_int_primitive ! ( u32 , f64 ) ;
1005
+
1006
+ impl_from_int_primitive ! ( i8 , f32 ) ;
1007
+ impl_from_int_primitive ! ( i16 , f32 ) ;
1008
+ impl_from_int_primitive ! ( u8 , f32 ) ;
1009
+ impl_from_int_primitive ! ( u16 , f32 ) ;
1010
+
987
1011
impl From < NotNan < f32 > > for NotNan < f64 > {
988
1012
#[ inline]
989
1013
fn from ( v : NotNan < f32 > ) -> NotNan < f64 > {
0 commit comments