1
1
use core:: mem:: size_of;
2
2
use core:: num:: Wrapping ;
3
3
use 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} ;
8
6
9
7
/// A generic trait for converting a value to a number.
10
8
///
@@ -53,12 +51,9 @@ pub trait ToPrimitive {
53
51
/// represented by an `i128` (`i64` under the default implementation), then
54
52
/// `None` is returned.
55
53
///
56
- /// This method is only available with feature `i128` enabled on Rust >= 1.26.
57
- ///
58
54
/// The default implementation converts through `to_i64()`. Types implementing
59
55
/// this trait should override this method if they can represent a greater range.
60
56
#[ inline]
61
- #[ cfg( has_i128) ]
62
57
fn to_i128 ( & self ) -> Option < i128 > {
63
58
self . to_i64 ( ) . map ( From :: from)
64
59
}
@@ -99,12 +94,9 @@ pub trait ToPrimitive {
99
94
/// represented by a `u128` (`u64` under the default implementation), then
100
95
/// `None` is returned.
101
96
///
102
- /// This method is only available with feature `i128` enabled on Rust >= 1.26.
103
- ///
104
97
/// The default implementation converts through `to_u64()`. Types implementing
105
98
/// this trait should override this method if they can represent a greater range.
106
99
#[ inline]
107
- #[ cfg( has_i128) ]
108
100
fn to_u128 ( & self ) -> Option < u128 > {
109
101
self . to_u64 ( ) . map ( From :: from)
110
102
}
@@ -173,7 +165,6 @@ macro_rules! impl_to_primitive_int {
173
165
fn to_i16 -> i16 ;
174
166
fn to_i32 -> i32 ;
175
167
fn to_i64 -> i64 ;
176
- #[ cfg( has_i128) ]
177
168
fn to_i128 -> i128 ;
178
169
}
179
170
@@ -183,7 +174,6 @@ macro_rules! impl_to_primitive_int {
183
174
fn to_u16 -> u16 ;
184
175
fn to_u32 -> u32 ;
185
176
fn to_u64 -> u64 ;
186
- #[ cfg( has_i128) ]
187
177
fn to_u128 -> u128 ;
188
178
}
189
179
@@ -204,7 +194,6 @@ impl_to_primitive_int!(i8);
204
194
impl_to_primitive_int ! ( i16 ) ;
205
195
impl_to_primitive_int ! ( i32 ) ;
206
196
impl_to_primitive_int ! ( i64 ) ;
207
- #[ cfg( has_i128) ]
208
197
impl_to_primitive_int ! ( i128 ) ;
209
198
210
199
macro_rules! impl_to_primitive_uint_to_int {
@@ -246,7 +235,6 @@ macro_rules! impl_to_primitive_uint {
246
235
fn to_i16 -> i16 ;
247
236
fn to_i32 -> i32 ;
248
237
fn to_i64 -> i64 ;
249
- #[ cfg( has_i128) ]
250
238
fn to_i128 -> i128 ;
251
239
}
252
240
@@ -256,7 +244,6 @@ macro_rules! impl_to_primitive_uint {
256
244
fn to_u16 -> u16 ;
257
245
fn to_u32 -> u32 ;
258
246
fn to_u64 -> u64 ;
259
- #[ cfg( has_i128) ]
260
247
fn to_u128 -> u128 ;
261
248
}
262
249
@@ -277,7 +264,6 @@ impl_to_primitive_uint!(u8);
277
264
impl_to_primitive_uint ! ( u16 ) ;
278
265
impl_to_primitive_uint ! ( u32 ) ;
279
266
impl_to_primitive_uint ! ( u64 ) ;
280
- #[ cfg( has_i128) ]
281
267
impl_to_primitive_uint ! ( u128 ) ;
282
268
283
269
macro_rules! impl_to_primitive_float_to_float {
@@ -373,7 +359,6 @@ macro_rules! impl_to_primitive_float {
373
359
fn to_i16 -> i16 ;
374
360
fn to_i32 -> i32 ;
375
361
fn to_i64 -> i64 ;
376
- #[ cfg( has_i128) ]
377
362
fn to_i128 -> i128 ;
378
363
}
379
364
@@ -383,7 +368,6 @@ macro_rules! impl_to_primitive_float {
383
368
fn to_u16 -> u16 ;
384
369
fn to_u32 -> u32 ;
385
370
fn to_u64 -> u64 ;
386
- #[ cfg( has_i128) ]
387
371
fn to_u128 -> u128 ;
388
372
}
389
373
@@ -444,12 +428,9 @@ pub trait FromPrimitive: Sized {
444
428
/// Converts an `i128` to return an optional value of this type. If the
445
429
/// value cannot be represented by this type, then `None` is returned.
446
430
///
447
- /// This method is only available with feature `i128` enabled on Rust >= 1.26.
448
- ///
449
431
/// The default implementation converts through `from_i64()`. Types implementing
450
432
/// this trait should override this method if they can represent a greater range.
451
433
#[ inline]
452
- #[ cfg( has_i128) ]
453
434
fn from_i128 ( n : i128 ) -> Option < Self > {
454
435
n. to_i64 ( ) . and_then ( FromPrimitive :: from_i64)
455
436
}
@@ -489,12 +470,9 @@ pub trait FromPrimitive: Sized {
489
470
/// Converts an `u128` to return an optional value of this type. If the
490
471
/// value cannot be represented by this type, then `None` is returned.
491
472
///
492
- /// This method is only available with feature `i128` enabled on Rust >= 1.26.
493
- ///
494
473
/// The default implementation converts through `from_u64()`. Types implementing
495
474
/// this trait should override this method if they can represent a greater range.
496
475
#[ inline]
497
- #[ cfg( has_i128) ]
498
476
fn from_u128 ( n : u128 ) -> Option < Self > {
499
477
n. to_u64 ( ) . and_then ( FromPrimitive :: from_u64)
500
478
}
@@ -545,7 +523,6 @@ macro_rules! impl_from_primitive {
545
523
fn from_i64( n: i64 ) -> Option <$T> {
546
524
n. $to_ty( )
547
525
}
548
- #[ cfg( has_i128) ]
549
526
#[ inline]
550
527
fn from_i128( n: i128 ) -> Option <$T> {
551
528
n. $to_ty( )
@@ -571,7 +548,6 @@ macro_rules! impl_from_primitive {
571
548
fn from_u64( n: u64 ) -> Option <$T> {
572
549
n. $to_ty( )
573
550
}
574
- #[ cfg( has_i128) ]
575
551
#[ inline]
576
552
fn from_u128( n: u128 ) -> Option <$T> {
577
553
n. $to_ty( )
@@ -594,14 +570,12 @@ impl_from_primitive!(i8, to_i8);
594
570
impl_from_primitive ! ( i16 , to_i16) ;
595
571
impl_from_primitive ! ( i32 , to_i32) ;
596
572
impl_from_primitive ! ( i64 , to_i64) ;
597
- #[ cfg( has_i128) ]
598
573
impl_from_primitive ! ( i128 , to_i128) ;
599
574
impl_from_primitive ! ( usize , to_usize) ;
600
575
impl_from_primitive ! ( u8 , to_u8) ;
601
576
impl_from_primitive ! ( u16 , to_u16) ;
602
577
impl_from_primitive ! ( u32 , to_u32) ;
603
578
impl_from_primitive ! ( u64 , to_u64) ;
604
- #[ cfg( has_i128) ]
605
579
impl_from_primitive ! ( u128 , to_u128) ;
606
580
impl_from_primitive ! ( f32 , to_f32) ;
607
581
impl_from_primitive ! ( f64 , to_f64) ;
@@ -623,15 +597,13 @@ impl<T: ToPrimitive> ToPrimitive for Wrapping<T> {
623
597
fn to_i16 -> i16 ;
624
598
fn to_i32 -> i32 ;
625
599
fn to_i64 -> i64 ;
626
- #[ cfg( has_i128) ]
627
600
fn to_i128 -> i128 ;
628
601
629
602
fn to_usize -> usize ;
630
603
fn to_u8 -> u8 ;
631
604
fn to_u16 -> u16 ;
632
605
fn to_u32 -> u32 ;
633
606
fn to_u64 -> u64 ;
634
- #[ cfg( has_i128) ]
635
607
fn to_u128 -> u128 ;
636
608
637
609
fn to_f32 -> f32 ;
@@ -656,15 +628,13 @@ impl<T: FromPrimitive> FromPrimitive for Wrapping<T> {
656
628
fn from_i16( i16 ) ;
657
629
fn from_i32( i32 ) ;
658
630
fn from_i64( i64 ) ;
659
- #[ cfg( has_i128) ]
660
631
fn from_i128( i128 ) ;
661
632
662
633
fn from_usize( usize ) ;
663
634
fn from_u8( u8 ) ;
664
635
fn from_u16( u16 ) ;
665
636
fn from_u32( u32 ) ;
666
637
fn from_u64( u64 ) ;
667
- #[ cfg( has_i128) ]
668
638
fn from_u128( u128 ) ;
669
639
670
640
fn from_f32( f32 ) ;
@@ -722,14 +692,12 @@ impl_num_cast!(u8, to_u8);
722
692
impl_num_cast ! ( u16 , to_u16) ;
723
693
impl_num_cast ! ( u32 , to_u32) ;
724
694
impl_num_cast ! ( u64 , to_u64) ;
725
- #[ cfg( has_i128) ]
726
695
impl_num_cast ! ( u128 , to_u128) ;
727
696
impl_num_cast ! ( usize , to_usize) ;
728
697
impl_num_cast ! ( i8 , to_i8) ;
729
698
impl_num_cast ! ( i16 , to_i16) ;
730
699
impl_num_cast ! ( i32 , to_i32) ;
731
700
impl_num_cast ! ( i64 , to_i64) ;
732
- #[ cfg( has_i128) ]
733
701
impl_num_cast ! ( i128 , to_i128) ;
734
702
impl_num_cast ! ( isize , to_isize) ;
735
703
impl_num_cast ! ( f32 , to_f32) ;
@@ -787,10 +755,8 @@ macro_rules! impl_as_primitive {
787
755
) * } ;
788
756
( $T: ty => { $( $U: ty ) ,* } ) => {
789
757
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 } ) ;
794
760
} ;
795
761
}
796
762
@@ -802,9 +768,7 @@ impl_as_primitive!(u32 => { f32, f64 });
802
768
impl_as_primitive ! ( i32 => { f32 , f64 } ) ;
803
769
impl_as_primitive ! ( u64 => { f32 , f64 } ) ;
804
770
impl_as_primitive ! ( i64 => { f32 , f64 } ) ;
805
- #[ cfg( has_i128) ]
806
771
impl_as_primitive ! ( u128 => { f32 , f64 } ) ;
807
- #[ cfg( has_i128) ]
808
772
impl_as_primitive ! ( i128 => { f32 , f64 } ) ;
809
773
impl_as_primitive ! ( usize => { f32 , f64 } ) ;
810
774
impl_as_primitive ! ( isize => { f32 , f64 } ) ;
0 commit comments