11use core:: mem:: size_of;
22use core:: num:: Wrapping ;
33use core:: { f32, f64} ;
4- #[ cfg( has_i128) ]
5- use core:: { i128, u128} ;
6- use core:: { i16, i32, i64, i8, isize} ;
7- use core:: { u16, u32, u64, u8, usize} ;
4+ use core:: { i128, i16, i32, i64, i8, isize} ;
5+ use core:: { u128, u16, u32, u64, u8, usize} ;
86
97/// A generic trait for converting a value to a number.
108///
@@ -53,12 +51,9 @@ pub trait ToPrimitive {
5351 /// represented by an `i128` (`i64` under the default implementation), then
5452 /// `None` is returned.
5553 ///
56- /// This method is only available with feature `i128` enabled on Rust >= 1.26.
57- ///
5854 /// The default implementation converts through `to_i64()`. Types implementing
5955 /// this trait should override this method if they can represent a greater range.
6056 #[ inline]
61- #[ cfg( has_i128) ]
6257 fn to_i128 ( & self ) -> Option < i128 > {
6358 self . to_i64 ( ) . map ( From :: from)
6459 }
@@ -99,12 +94,9 @@ pub trait ToPrimitive {
9994 /// represented by a `u128` (`u64` under the default implementation), then
10095 /// `None` is returned.
10196 ///
102- /// This method is only available with feature `i128` enabled on Rust >= 1.26.
103- ///
10497 /// The default implementation converts through `to_u64()`. Types implementing
10598 /// this trait should override this method if they can represent a greater range.
10699 #[ inline]
107- #[ cfg( has_i128) ]
108100 fn to_u128 ( & self ) -> Option < u128 > {
109101 self . to_u64 ( ) . map ( From :: from)
110102 }
@@ -173,7 +165,6 @@ macro_rules! impl_to_primitive_int {
173165 fn to_i16 -> i16 ;
174166 fn to_i32 -> i32 ;
175167 fn to_i64 -> i64 ;
176- #[ cfg( has_i128) ]
177168 fn to_i128 -> i128 ;
178169 }
179170
@@ -183,7 +174,6 @@ macro_rules! impl_to_primitive_int {
183174 fn to_u16 -> u16 ;
184175 fn to_u32 -> u32 ;
185176 fn to_u64 -> u64 ;
186- #[ cfg( has_i128) ]
187177 fn to_u128 -> u128 ;
188178 }
189179
@@ -204,7 +194,6 @@ impl_to_primitive_int!(i8);
204194impl_to_primitive_int ! ( i16 ) ;
205195impl_to_primitive_int ! ( i32 ) ;
206196impl_to_primitive_int ! ( i64 ) ;
207- #[ cfg( has_i128) ]
208197impl_to_primitive_int ! ( i128 ) ;
209198
210199macro_rules! impl_to_primitive_uint_to_int {
@@ -246,7 +235,6 @@ macro_rules! impl_to_primitive_uint {
246235 fn to_i16 -> i16 ;
247236 fn to_i32 -> i32 ;
248237 fn to_i64 -> i64 ;
249- #[ cfg( has_i128) ]
250238 fn to_i128 -> i128 ;
251239 }
252240
@@ -256,7 +244,6 @@ macro_rules! impl_to_primitive_uint {
256244 fn to_u16 -> u16 ;
257245 fn to_u32 -> u32 ;
258246 fn to_u64 -> u64 ;
259- #[ cfg( has_i128) ]
260247 fn to_u128 -> u128 ;
261248 }
262249
@@ -277,7 +264,6 @@ impl_to_primitive_uint!(u8);
277264impl_to_primitive_uint ! ( u16 ) ;
278265impl_to_primitive_uint ! ( u32 ) ;
279266impl_to_primitive_uint ! ( u64 ) ;
280- #[ cfg( has_i128) ]
281267impl_to_primitive_uint ! ( u128 ) ;
282268
283269macro_rules! impl_to_primitive_float_to_float {
@@ -373,7 +359,6 @@ macro_rules! impl_to_primitive_float {
373359 fn to_i16 -> i16 ;
374360 fn to_i32 -> i32 ;
375361 fn to_i64 -> i64 ;
376- #[ cfg( has_i128) ]
377362 fn to_i128 -> i128 ;
378363 }
379364
@@ -383,7 +368,6 @@ macro_rules! impl_to_primitive_float {
383368 fn to_u16 -> u16 ;
384369 fn to_u32 -> u32 ;
385370 fn to_u64 -> u64 ;
386- #[ cfg( has_i128) ]
387371 fn to_u128 -> u128 ;
388372 }
389373
@@ -444,12 +428,9 @@ pub trait FromPrimitive: Sized {
444428 /// Converts an `i128` to return an optional value of this type. If the
445429 /// value cannot be represented by this type, then `None` is returned.
446430 ///
447- /// This method is only available with feature `i128` enabled on Rust >= 1.26.
448- ///
449431 /// The default implementation converts through `from_i64()`. Types implementing
450432 /// this trait should override this method if they can represent a greater range.
451433 #[ inline]
452- #[ cfg( has_i128) ]
453434 fn from_i128 ( n : i128 ) -> Option < Self > {
454435 n. to_i64 ( ) . and_then ( FromPrimitive :: from_i64)
455436 }
@@ -489,12 +470,9 @@ pub trait FromPrimitive: Sized {
489470 /// Converts an `u128` to return an optional value of this type. If the
490471 /// value cannot be represented by this type, then `None` is returned.
491472 ///
492- /// This method is only available with feature `i128` enabled on Rust >= 1.26.
493- ///
494473 /// The default implementation converts through `from_u64()`. Types implementing
495474 /// this trait should override this method if they can represent a greater range.
496475 #[ inline]
497- #[ cfg( has_i128) ]
498476 fn from_u128 ( n : u128 ) -> Option < Self > {
499477 n. to_u64 ( ) . and_then ( FromPrimitive :: from_u64)
500478 }
@@ -545,7 +523,6 @@ macro_rules! impl_from_primitive {
545523 fn from_i64( n: i64 ) -> Option <$T> {
546524 n. $to_ty( )
547525 }
548- #[ cfg( has_i128) ]
549526 #[ inline]
550527 fn from_i128( n: i128 ) -> Option <$T> {
551528 n. $to_ty( )
@@ -571,7 +548,6 @@ macro_rules! impl_from_primitive {
571548 fn from_u64( n: u64 ) -> Option <$T> {
572549 n. $to_ty( )
573550 }
574- #[ cfg( has_i128) ]
575551 #[ inline]
576552 fn from_u128( n: u128 ) -> Option <$T> {
577553 n. $to_ty( )
@@ -594,14 +570,12 @@ impl_from_primitive!(i8, to_i8);
594570impl_from_primitive ! ( i16 , to_i16) ;
595571impl_from_primitive ! ( i32 , to_i32) ;
596572impl_from_primitive ! ( i64 , to_i64) ;
597- #[ cfg( has_i128) ]
598573impl_from_primitive ! ( i128 , to_i128) ;
599574impl_from_primitive ! ( usize , to_usize) ;
600575impl_from_primitive ! ( u8 , to_u8) ;
601576impl_from_primitive ! ( u16 , to_u16) ;
602577impl_from_primitive ! ( u32 , to_u32) ;
603578impl_from_primitive ! ( u64 , to_u64) ;
604- #[ cfg( has_i128) ]
605579impl_from_primitive ! ( u128 , to_u128) ;
606580impl_from_primitive ! ( f32 , to_f32) ;
607581impl_from_primitive ! ( f64 , to_f64) ;
@@ -623,15 +597,13 @@ impl<T: ToPrimitive> ToPrimitive for Wrapping<T> {
623597 fn to_i16 -> i16 ;
624598 fn to_i32 -> i32 ;
625599 fn to_i64 -> i64 ;
626- #[ cfg( has_i128) ]
627600 fn to_i128 -> i128 ;
628601
629602 fn to_usize -> usize ;
630603 fn to_u8 -> u8 ;
631604 fn to_u16 -> u16 ;
632605 fn to_u32 -> u32 ;
633606 fn to_u64 -> u64 ;
634- #[ cfg( has_i128) ]
635607 fn to_u128 -> u128 ;
636608
637609 fn to_f32 -> f32 ;
@@ -656,15 +628,13 @@ impl<T: FromPrimitive> FromPrimitive for Wrapping<T> {
656628 fn from_i16( i16 ) ;
657629 fn from_i32( i32 ) ;
658630 fn from_i64( i64 ) ;
659- #[ cfg( has_i128) ]
660631 fn from_i128( i128 ) ;
661632
662633 fn from_usize( usize ) ;
663634 fn from_u8( u8 ) ;
664635 fn from_u16( u16 ) ;
665636 fn from_u32( u32 ) ;
666637 fn from_u64( u64 ) ;
667- #[ cfg( has_i128) ]
668638 fn from_u128( u128 ) ;
669639
670640 fn from_f32( f32 ) ;
@@ -722,14 +692,12 @@ impl_num_cast!(u8, to_u8);
722692impl_num_cast ! ( u16 , to_u16) ;
723693impl_num_cast ! ( u32 , to_u32) ;
724694impl_num_cast ! ( u64 , to_u64) ;
725- #[ cfg( has_i128) ]
726695impl_num_cast ! ( u128 , to_u128) ;
727696impl_num_cast ! ( usize , to_usize) ;
728697impl_num_cast ! ( i8 , to_i8) ;
729698impl_num_cast ! ( i16 , to_i16) ;
730699impl_num_cast ! ( i32 , to_i32) ;
731700impl_num_cast ! ( i64 , to_i64) ;
732- #[ cfg( has_i128) ]
733701impl_num_cast ! ( i128 , to_i128) ;
734702impl_num_cast ! ( isize , to_isize) ;
735703impl_num_cast ! ( f32 , to_f32) ;
@@ -787,10 +755,8 @@ macro_rules! impl_as_primitive {
787755 ) * } ;
788756 ( $T: ty => { $( $U: ty ) ,* } ) => {
789757 impl_as_primitive!( @ $T => { $( $U ) ,* } ) ;
790- impl_as_primitive!( @ $T => { u8 , u16 , u32 , u64 , usize } ) ;
791- impl_as_primitive!( @ $T => #[ cfg( has_i128) ] impl u128 ) ;
792- impl_as_primitive!( @ $T => { i8 , i16 , i32 , i64 , isize } ) ;
793- impl_as_primitive!( @ $T => #[ cfg( has_i128) ] impl i128 ) ;
758+ impl_as_primitive!( @ $T => { u8 , u16 , u32 , u64 , u128 , usize } ) ;
759+ impl_as_primitive!( @ $T => { i8 , i16 , i32 , i64 , i128 , isize } ) ;
794760 } ;
795761}
796762
@@ -802,9 +768,7 @@ impl_as_primitive!(u32 => { f32, f64 });
802768impl_as_primitive ! ( i32 => { f32 , f64 } ) ;
803769impl_as_primitive ! ( u64 => { f32 , f64 } ) ;
804770impl_as_primitive ! ( i64 => { f32 , f64 } ) ;
805- #[ cfg( has_i128) ]
806771impl_as_primitive ! ( u128 => { f32 , f64 } ) ;
807- #[ cfg( has_i128) ]
808772impl_as_primitive ! ( i128 => { f32 , f64 } ) ;
809773impl_as_primitive ! ( usize => { f32 , f64 } ) ;
810774impl_as_primitive ! ( isize => { f32 , f64 } ) ;
0 commit comments