@@ -30,7 +30,7 @@ use option::Option::{Some, None};
30
30
use str:: { FromStr , StrExt } ;
31
31
32
32
/// A built-in signed or unsigned integer.
33
- #[ unstable = "recently settled as part of numerics reform" ]
33
+ #[ stable ]
34
34
pub trait Int
35
35
: Copy + Clone
36
36
+ NumCast
@@ -50,18 +50,22 @@ pub trait Int
50
50
{
51
51
/// Returns the `0` value of this integer type.
52
52
// FIXME (#5527): Should be an associated constant
53
+ #[ unstable = "unsure about its place in the world" ]
53
54
fn zero ( ) -> Self ;
54
55
55
56
/// Returns the `1` value of this integer type.
56
57
// FIXME (#5527): Should be an associated constant
58
+ #[ unstable = "unsure about its place in the world" ]
57
59
fn one ( ) -> Self ;
58
60
59
61
/// Returns the smallest value that can be represented by this integer type.
60
62
// FIXME (#5527): Should be and associated constant
63
+ #[ unstable = "unsure about its place in the world" ]
61
64
fn min_value ( ) -> Self ;
62
65
63
66
/// Returns the largest value that can be represented by this integer type.
64
67
// FIXME (#5527): Should be and associated constant
68
+ #[ unstable = "unsure about its place in the world" ]
65
69
fn max_value ( ) -> Self ;
66
70
67
71
/// Returns the number of ones in the binary representation of `self`.
@@ -75,6 +79,7 @@ pub trait Int
75
79
///
76
80
/// assert_eq!(n.count_ones(), 3);
77
81
/// ```
82
+ #[ unstable = "pending integer conventions" ]
78
83
fn count_ones ( self ) -> uint ;
79
84
80
85
/// Returns the number of zeros in the binary representation of `self`.
@@ -88,6 +93,7 @@ pub trait Int
88
93
///
89
94
/// assert_eq!(n.count_zeros(), 5);
90
95
/// ```
96
+ #[ unstable = "pending integer conventions" ]
91
97
#[ inline]
92
98
fn count_zeros ( self ) -> uint {
93
99
( !self ) . count_ones ( )
@@ -105,6 +111,7 @@ pub trait Int
105
111
///
106
112
/// assert_eq!(n.leading_zeros(), 10);
107
113
/// ```
114
+ #[ unstable = "pending integer conventions" ]
108
115
fn leading_zeros ( self ) -> uint ;
109
116
110
117
/// Returns the number of trailing zeros in the binary representation
@@ -119,6 +126,7 @@ pub trait Int
119
126
///
120
127
/// assert_eq!(n.trailing_zeros(), 3);
121
128
/// ```
129
+ #[ unstable = "pending integer conventions" ]
122
130
fn trailing_zeros ( self ) -> uint ;
123
131
124
132
/// Shifts the bits to the left by a specified amount amount, `n`, wrapping
@@ -134,6 +142,7 @@ pub trait Int
134
142
///
135
143
/// assert_eq!(n.rotate_left(12), m);
136
144
/// ```
145
+ #[ unstable = "pending integer conventions" ]
137
146
fn rotate_left ( self , n : uint ) -> Self ;
138
147
139
148
/// Shifts the bits to the right by a specified amount amount, `n`, wrapping
@@ -149,6 +158,7 @@ pub trait Int
149
158
///
150
159
/// assert_eq!(n.rotate_right(12), m);
151
160
/// ```
161
+ #[ unstable = "pending integer conventions" ]
152
162
fn rotate_right ( self , n : uint ) -> Self ;
153
163
154
164
/// Reverses the byte order of the integer.
@@ -163,6 +173,7 @@ pub trait Int
163
173
///
164
174
/// assert_eq!(n.swap_bytes(), m);
165
175
/// ```
176
+ #[ stable]
166
177
fn swap_bytes ( self ) -> Self ;
167
178
168
179
/// Convert an integer from big endian to the target's endianness.
@@ -182,6 +193,7 @@ pub trait Int
182
193
/// assert_eq!(Int::from_be(n), n.swap_bytes())
183
194
/// }
184
195
/// ```
196
+ #[ stable]
185
197
#[ inline]
186
198
fn from_be ( x : Self ) -> Self {
187
199
if cfg ! ( target_endian = "big" ) { x } else { x. swap_bytes ( ) }
@@ -204,6 +216,7 @@ pub trait Int
204
216
/// assert_eq!(Int::from_le(n), n.swap_bytes())
205
217
/// }
206
218
/// ```
219
+ #[ stable]
207
220
#[ inline]
208
221
fn from_le ( x : Self ) -> Self {
209
222
if cfg ! ( target_endian = "little" ) { x } else { x. swap_bytes ( ) }
@@ -226,6 +239,7 @@ pub trait Int
226
239
/// assert_eq!(n.to_be(), n.swap_bytes())
227
240
/// }
228
241
/// ```
242
+ #[ stable]
229
243
#[ inline]
230
244
fn to_be ( self ) -> Self { // or not to be?
231
245
if cfg ! ( target_endian = "big" ) { self } else { self . swap_bytes ( ) }
@@ -248,6 +262,7 @@ pub trait Int
248
262
/// assert_eq!(n.to_le(), n.swap_bytes())
249
263
/// }
250
264
/// ```
265
+ #[ stable]
251
266
#[ inline]
252
267
fn to_le ( self ) -> Self {
253
268
if cfg ! ( target_endian = "little" ) { self } else { self . swap_bytes ( ) }
@@ -264,6 +279,7 @@ pub trait Int
264
279
/// assert_eq!(5u16.checked_add(65530), Some(65535));
265
280
/// assert_eq!(6u16.checked_add(65530), None);
266
281
/// ```
282
+ #[ stable]
267
283
fn checked_add ( self , other : Self ) -> Option < Self > ;
268
284
269
285
/// Checked integer subtraction. Computes `self - other`, returning `None`
@@ -277,6 +293,7 @@ pub trait Int
277
293
/// assert_eq!((-127i8).checked_sub(1), Some(-128));
278
294
/// assert_eq!((-128i8).checked_sub(1), None);
279
295
/// ```
296
+ #[ stable]
280
297
fn checked_sub ( self , other : Self ) -> Option < Self > ;
281
298
282
299
/// Checked integer multiplication. Computes `self * other`, returning
@@ -290,6 +307,7 @@ pub trait Int
290
307
/// assert_eq!(5u8.checked_mul(51), Some(255));
291
308
/// assert_eq!(5u8.checked_mul(52), None);
292
309
/// ```
310
+ #[ stable]
293
311
fn checked_mul ( self , other : Self ) -> Option < Self > ;
294
312
295
313
/// Checked integer division. Computes `self / other`, returning `None` if
@@ -304,11 +322,12 @@ pub trait Int
304
322
/// assert_eq!((-128i8).checked_div(-1), None);
305
323
/// assert_eq!((1i8).checked_div(0), None);
306
324
/// ```
307
- #[ inline ]
325
+ #[ stable ]
308
326
fn checked_div ( self , other : Self ) -> Option < Self > ;
309
327
310
328
/// Saturating integer addition. Computes `self + other`, saturating at
311
329
/// the numeric bounds instead of overflowing.
330
+ #[ stable]
312
331
#[ inline]
313
332
fn saturating_add ( self , other : Self ) -> Self {
314
333
match self . checked_add ( other) {
@@ -320,6 +339,7 @@ pub trait Int
320
339
321
340
/// Saturating integer subtraction. Computes `self - other`, saturating at
322
341
/// the numeric bounds instead of overflowing.
342
+ #[ stable]
323
343
#[ inline]
324
344
fn saturating_sub ( self , other : Self ) -> Self {
325
345
match self . checked_sub ( other) {
@@ -338,6 +358,7 @@ pub trait Int
338
358
///
339
359
/// assert_eq!(2i.pow(4), 16);
340
360
/// ```
361
+ #[ unstable = "pending integer conventions" ]
341
362
#[ inline]
342
363
fn pow ( self , mut exp : uint ) -> Self {
343
364
let mut base = self ;
@@ -369,7 +390,7 @@ macro_rules! uint_impl {
369
390
$add_with_overflow: path,
370
391
$sub_with_overflow: path,
371
392
$mul_with_overflow: path) => {
372
- #[ unstable = "trait is unstable" ]
393
+ #[ stable ]
373
394
impl Int for $T {
374
395
#[ inline]
375
396
fn zero( ) -> $T { 0 }
@@ -500,7 +521,7 @@ macro_rules! int_impl {
500
521
$add_with_overflow: path,
501
522
$sub_with_overflow: path,
502
523
$mul_with_overflow: path) => {
503
- #[ unstable = "trait is unstable" ]
524
+ #[ stable ]
504
525
impl Int for $T {
505
526
#[ inline]
506
527
fn zero( ) -> $T { 0 }
@@ -593,33 +614,38 @@ int_impl! { int = i64, u64, 64,
593
614
intrinsics:: i64_mul_with_overflow }
594
615
595
616
/// A built-in two's complement integer.
596
- #[ unstable = "recently settled as part of numerics reform" ]
617
+ #[ stable ]
597
618
pub trait SignedInt
598
619
: Int
599
620
+ Neg < Output =Self >
600
621
{
601
622
/// Computes the absolute value of `self`. `Int::min_value()` will be
602
623
/// returned if the number is `Int::min_value()`.
624
+ #[ unstable = "overflow in debug builds?" ]
603
625
fn abs ( self ) -> Self ;
604
626
605
627
/// Returns a number representing sign of `self`.
606
628
///
607
629
/// - `0` if the number is zero
608
630
/// - `1` if the number is positive
609
631
/// - `-1` if the number is negative
632
+ #[ stable]
610
633
fn signum ( self ) -> Self ;
611
634
612
635
/// Returns `true` if `self` is positive and `false` if the number
613
636
/// is zero or negative.
637
+ #[ stable]
614
638
fn is_positive ( self ) -> bool ;
615
639
616
640
/// Returns `true` if `self` is negative and `false` if the number
617
641
/// is zero or positive.
642
+ #[ stable]
618
643
fn is_negative ( self ) -> bool ;
619
644
}
620
645
621
646
macro_rules! signed_int_impl {
622
647
( $T: ty) => {
648
+ #[ stable]
623
649
impl SignedInt for $T {
624
650
#[ inline]
625
651
fn abs( self ) -> $T {
@@ -651,16 +677,18 @@ signed_int_impl! { i64 }
651
677
signed_int_impl ! { int }
652
678
653
679
/// A built-in unsigned integer.
654
- #[ unstable = "recently settled as part of numerics reform" ]
680
+ #[ stable ]
655
681
pub trait UnsignedInt : Int {
656
682
/// Returns `true` iff `self == 2^k` for some `k`.
683
+ #[ stable]
657
684
#[ inline]
658
685
fn is_power_of_two ( self ) -> bool {
659
686
( self - Int :: one ( ) ) & self == Int :: zero ( ) && !( self == Int :: zero ( ) )
660
687
}
661
688
662
689
/// Returns the smallest power of two greater than or equal to `self`.
663
690
/// Unspecified behavior on overflow.
691
+ #[ stable]
664
692
#[ inline]
665
693
fn next_power_of_two ( self ) -> Self {
666
694
let bits = size_of :: < Self > ( ) * 8 ;
@@ -671,6 +699,7 @@ pub trait UnsignedInt: Int {
671
699
/// Returns the smallest power of two greater than or equal to `n`. If the
672
700
/// next power of two is greater than the type's maximum value, `None` is
673
701
/// returned, otherwise the power of two is wrapped in `Some`.
702
+ #[ stable]
674
703
fn checked_next_power_of_two ( self ) -> Option < Self > {
675
704
let npot = self . next_power_of_two ( ) ;
676
705
if npot >= self {
@@ -681,19 +710,19 @@ pub trait UnsignedInt: Int {
681
710
}
682
711
}
683
712
684
- #[ unstable = "trait is unstable" ]
713
+ #[ stable ]
685
714
impl UnsignedInt for uint { }
686
715
687
- #[ unstable = "trait is unstable" ]
716
+ #[ stable ]
688
717
impl UnsignedInt for u8 { }
689
718
690
- #[ unstable = "trait is unstable" ]
719
+ #[ stable ]
691
720
impl UnsignedInt for u16 { }
692
721
693
- #[ unstable = "trait is unstable" ]
722
+ #[ stable ]
694
723
impl UnsignedInt for u32 { }
695
724
696
- #[ unstable = "trait is unstable" ]
725
+ #[ stable ]
697
726
impl UnsignedInt for u64 { }
698
727
699
728
/// A generic trait for converting a value to a number.
0 commit comments