@@ -188,7 +188,8 @@ mod wrapping;
188
188
// `Int` + `SignedInt` implemented for signed integers
189
189
macro_rules! int_impl {
190
190
( $SelfT: ty, $ActualT: ident, $UnsignedT: ty, $BITS: expr, $Min: expr, $Max: expr, $Feature: expr,
191
- $EndFeature: expr, $rot: expr, $rot_op: expr, $rot_result: expr) => {
191
+ $EndFeature: expr, $rot: expr, $rot_op: expr, $rot_result: expr, $swap_op: expr, $swapped: expr,
192
+ $reversed: expr) => {
192
193
doc_comment! {
193
194
concat!( "Returns the smallest value that can be represented by this integer type.
194
195
@@ -380,55 +381,48 @@ assert_eq!(n.rotate_right(", $rot, "), m);
380
381
( self as $UnsignedT) . rotate_right( n) as Self
381
382
}
382
383
}
383
- /// Reverses the byte order of the integer.
384
- ///
385
- /// # Examples
386
- ///
387
- /// Please note that this example is shared between integer types.
388
- /// Which explains why `i16` is used here.
389
- ///
390
- /// Basic usage:
391
- ///
392
- /// ```
393
- /// let n: i16 = 0b0000000_01010101;
394
- /// assert_eq!(n, 85);
395
- ///
396
- /// let m = n.swap_bytes();
397
- ///
398
- /// assert_eq!(m, 0b01010101_00000000);
399
- /// assert_eq!(m, 21760);
400
- /// ```
401
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
402
- #[ rustc_const_unstable( feature = "const_int_ops" ) ]
403
- #[ inline]
404
- pub const fn swap_bytes( self ) -> Self {
405
- ( self as $UnsignedT) . swap_bytes( ) as Self
384
+ doc_comment! {
385
+ concat!( "Reverses the byte order of the integer.
386
+
387
+ # Examples
388
+
389
+ Basic usage:
390
+
391
+ ```
392
+ let n = " , $swap_op, stringify!( $SelfT) , ";
393
+
394
+ let m = n.swap_bytes();
395
+
396
+ assert_eq!(m, " , $swapped, ");
397
+ ```" ) ,
398
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
399
+ #[ rustc_const_unstable( feature = "const_int_ops" ) ]
400
+ #[ inline]
401
+ pub const fn swap_bytes( self ) -> Self {
402
+ ( self as $UnsignedT) . swap_bytes( ) as Self
403
+ }
406
404
}
407
405
408
- /// Reverses the bit pattern of the integer.
409
- ///
410
- /// # Examples
411
- ///
412
- /// Please note that this example is shared between integer types.
413
- /// Which explains why `i16` is used here.
414
- ///
415
- /// Basic usage:
416
- ///
417
- /// ```
418
- /// #![feature(reverse_bits)]
419
- ///
420
- /// let n: i16 = 0b0000000_01010101;
421
- /// assert_eq!(n, 85);
422
- ///
423
- /// let m = n.reverse_bits();
424
- ///
425
- /// assert_eq!(m as u16, 0b10101010_00000000);
426
- /// assert_eq!(m, -22016);
427
- /// ```
428
- #[ unstable( feature = "reverse_bits" , issue = "48763" ) ]
429
- #[ inline]
430
- pub fn reverse_bits( self ) -> Self {
431
- ( self as $UnsignedT) . reverse_bits( ) as Self
406
+ doc_comment! {
407
+ concat!( "Reverses the bit pattern of the integer.
408
+
409
+ # Examples
410
+
411
+ Basic usage:
412
+
413
+ ```
414
+ #![feature(reverse_bits)]
415
+
416
+ let n = " , $swap_op, stringify!( $SelfT) , ";
417
+ let m = n.reverse_bits();
418
+
419
+ assert_eq!(m, " , $reversed, ");
420
+ ```" ) ,
421
+ #[ unstable( feature = "reverse_bits" , issue = "48763" ) ]
422
+ #[ inline]
423
+ pub fn reverse_bits( self ) -> Self {
424
+ ( self as $UnsignedT) . reverse_bits( ) as Self
425
+ }
432
426
}
433
427
434
428
doc_comment! {
@@ -2009,50 +2003,57 @@ $EndFeature, "
2009
2003
2010
2004
#[ lang = "i8" ]
2011
2005
impl i8 {
2012
- int_impl ! { i8 , i8 , u8 , 8 , -128 , 127 , "" , "" , 2 , "-0x7e" , "0xa" }
2006
+ int_impl ! { i8 , i8 , u8 , 8 , -128 , 127 , "" , "" , 2 , "-0x7e" , "0xa" , "0x12" , "0x12" , "0x48" }
2013
2007
}
2014
2008
2015
2009
#[ lang = "i16" ]
2016
2010
impl i16 {
2017
- int_impl ! { i16 , i16 , u16 , 16 , -32768 , 32767 , "" , "" , 4 , "-0x5ffd" , "0x3a" }
2011
+ int_impl ! { i16 , i16 , u16 , 16 , -32768 , 32767 , "" , "" , 4 , "-0x5ffd" , "0x3a" , "0x1234" , "0x3412" ,
2012
+ "0x2c48" }
2018
2013
}
2019
2014
2020
2015
#[ lang = "i32" ]
2021
2016
impl i32 {
2022
- int_impl ! { i32 , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" , 8 , "0x10000b3" , "0xb301" }
2017
+ int_impl ! { i32 , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" , 8 , "0x10000b3" , "0xb301" ,
2018
+ "0x12345678" , "0x78563412" , "0x1e6a2c48" }
2023
2019
}
2024
2020
2025
2021
#[ lang = "i64" ]
2026
2022
impl i64 {
2027
2023
int_impl ! { i64 , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" , 12 ,
2028
- "0xaa00000000006e1" , "0x6e10aa" }
2024
+ "0xaa00000000006e1" , "0x6e10aa" , "0x1234567890123456" , "0x5634129078563412" ,
2025
+ "0x6a2c48091e6a2c48" }
2029
2026
}
2030
2027
2031
2028
#[ lang = "i128" ]
2032
2029
impl i128 {
2033
2030
int_impl ! { i128 , i128 , u128 , 128 , -170141183460469231731687303715884105728 ,
2034
2031
170141183460469231731687303715884105727 , "" , "" , 16 ,
2035
- "0x13f40000000000000000000000004f76" , "0x4f7613f4"
2032
+ "0x13f40000000000000000000000004f76" , "0x4f7613f4" , "0x12345678901234567890123456789012" ,
2033
+ "0x12907856341290785634129078563412" , "0x48091e6a2c48091e6a2c48091e6a2c48"
2036
2034
}
2037
2035
}
2038
2036
2039
2037
#[ cfg( target_pointer_width = "16" ) ]
2040
2038
#[ lang = "isize" ]
2041
2039
impl isize {
2042
- int_impl ! { isize , i16 , u16 , 16 , -32768 , 32767 , "" , "" , 4 , "-0x5ffd" , "0x3a" }
2040
+ int_impl ! { isize , i16 , u16 , 16 , -32768 , 32767 , "" , "" , 4 , "-0x5ffd" , "0x3a" , "0x1234" ,
2041
+ "0x3412" , "0x2c48" }
2043
2042
}
2044
2043
2045
2044
#[ cfg( target_pointer_width = "32" ) ]
2046
2045
#[ lang = "isize" ]
2047
2046
impl isize {
2048
- int_impl ! { isize , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" , 8 , "0x10000b3" , "0xb301" }
2047
+ int_impl ! { isize , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" , 8 , "0x10000b3" , "0xb301" ,
2048
+ "0x12345678" , "0x78563412" , "0x1e6a2c48" }
2049
2049
}
2050
2050
2051
2051
#[ cfg( target_pointer_width = "64" ) ]
2052
2052
#[ lang = "isize" ]
2053
2053
impl isize {
2054
2054
int_impl ! { isize , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" ,
2055
- 12 , "0xaa00000000006e1" , "0x6e10aa" }
2055
+ 12 , "0xaa00000000006e1" , "0x6e10aa" , "0x1234567890123456" , "0x5634129078563412" ,
2056
+ "0x6a2c48091e6a2c48" }
2056
2057
}
2057
2058
2058
2059
// Emits the correct `cttz` call, depending on the size of the type.
@@ -2071,7 +2072,8 @@ macro_rules! uint_cttz_call {
2071
2072
// `Int` + `UnsignedInt` implemented for unsigned integers
2072
2073
macro_rules! uint_impl {
2073
2074
( $SelfT: ty, $ActualT: ty, $BITS: expr, $MaxV: expr, $Feature: expr, $EndFeature: expr,
2074
- $rot: expr, $rot_op: expr, $rot_result: expr) => {
2075
+ $rot: expr, $rot_op: expr, $rot_result: expr, $swap_op: expr, $swapped: expr,
2076
+ $reversed: expr ) => {
2075
2077
doc_comment! {
2076
2078
concat!( "Returns the smallest value that can be represented by this integer type.
2077
2079
@@ -2263,55 +2265,48 @@ assert_eq!(n.rotate_right(", $rot, "), m);
2263
2265
}
2264
2266
}
2265
2267
2266
- /// Reverses the byte order of the integer.
2267
- ///
2268
- /// # Examples
2269
- ///
2270
- /// Basic usage:
2271
- ///
2272
- /// Please note that this example is shared between integer types.
2273
- /// Which explains why `u16` is used here.
2274
- ///
2275
- /// ```
2276
- /// let n: u16 = 0b0000000_01010101;
2277
- /// assert_eq!(n, 85);
2278
- ///
2279
- /// let m = n.swap_bytes();
2280
- ///
2281
- /// assert_eq!(m, 0b01010101_00000000);
2282
- /// assert_eq!(m, 21760);
2283
- /// ```
2284
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2285
- #[ rustc_const_unstable( feature = "const_int_ops" ) ]
2286
- #[ inline]
2287
- pub const fn swap_bytes( self ) -> Self {
2288
- unsafe { intrinsics:: bswap( self as $ActualT) as Self }
2268
+ doc_comment! {
2269
+ concat!( "
2270
+ Reverses the byte order of the integer.
2271
+
2272
+ # Examples
2273
+
2274
+ Basic usage:
2275
+
2276
+ ```
2277
+ let n = " , $swap_op, stringify!( $SelfT) , ";
2278
+ let m = n.swap_bytes();
2279
+
2280
+ assert_eq!(m, " , $swapped, ");
2281
+ ```" ) ,
2282
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2283
+ #[ rustc_const_unstable( feature = "const_int_ops" ) ]
2284
+ #[ inline]
2285
+ pub const fn swap_bytes( self ) -> Self {
2286
+ unsafe { intrinsics:: bswap( self as $ActualT) as Self }
2287
+ }
2289
2288
}
2290
2289
2291
- /// Reverses the bit pattern of the integer.
2292
- ///
2293
- /// # Examples
2294
- ///
2295
- /// Basic usage:
2296
- ///
2297
- /// Please note that this example is shared between integer types.
2298
- /// Which explains why `u16` is used here.
2299
- ///
2300
- /// ```
2301
- /// #![feature(reverse_bits)]
2302
- ///
2303
- /// let n: u16 = 0b0000000_01010101;
2304
- /// assert_eq!(n, 85);
2305
- ///
2306
- /// let m = n.reverse_bits();
2307
- ///
2308
- /// assert_eq!(m, 0b10101010_00000000);
2309
- /// assert_eq!(m, 43520);
2310
- /// ```
2311
- #[ unstable( feature = "reverse_bits" , issue = "48763" ) ]
2312
- #[ inline]
2313
- pub fn reverse_bits( self ) -> Self {
2314
- unsafe { intrinsics:: bitreverse( self as $ActualT) as Self }
2290
+ doc_comment! {
2291
+ concat!( "Reverses the bit pattern of the integer.
2292
+
2293
+ # Examples
2294
+
2295
+ Basic usage:
2296
+
2297
+ ```
2298
+ #![feature(reverse_bits)]
2299
+
2300
+ let n = " , $swap_op, stringify!( $SelfT) , ";
2301
+ let m = n.reverse_bits();
2302
+
2303
+ assert_eq!(m, " , $reversed, ");
2304
+ ```" ) ,
2305
+ #[ unstable( feature = "reverse_bits" , issue = "48763" ) ]
2306
+ #[ inline]
2307
+ pub fn reverse_bits( self ) -> Self {
2308
+ unsafe { intrinsics:: bitreverse( self as $ActualT) as Self }
2309
+ }
2315
2310
}
2316
2311
2317
2312
doc_comment! {
@@ -3621,7 +3616,7 @@ $EndFeature, "
3621
3616
3622
3617
#[ lang = "u8" ]
3623
3618
impl u8 {
3624
- uint_impl ! { u8 , u8 , 8 , 255 , "" , "" , 2 , "0x82" , "0xa" }
3619
+ uint_impl ! { u8 , u8 , 8 , 255 , "" , "" , 2 , "0x82" , "0xa" , "0x12" , "0x12" , "0x48" }
3625
3620
3626
3621
3627
3622
/// Checks if the value is within the ASCII range.
@@ -4147,41 +4142,45 @@ impl u8 {
4147
4142
4148
4143
#[ lang = "u16" ]
4149
4144
impl u16 {
4150
- uint_impl ! { u16 , u16 , 16 , 65535 , "" , "" , 4 , "0xa003" , "0x3a" }
4145
+ uint_impl ! { u16 , u16 , 16 , 65535 , "" , "" , 4 , "0xa003" , "0x3a" , "0x1234" , "0x3412" , "0x2c48" }
4151
4146
}
4152
4147
4153
4148
#[ lang = "u32" ]
4154
4149
impl u32 {
4155
- uint_impl ! { u32 , u32 , 32 , 4294967295 , "" , "" , 8 , "0x10000b3" , "0xb301" }
4150
+ uint_impl ! { u32 , u32 , 32 , 4294967295 , "" , "" , 8 , "0x10000b3" , "0xb301" , "0x12345678" ,
4151
+ "0x78563412" , "0x1e6a2c48" }
4156
4152
}
4157
4153
4158
4154
#[ lang = "u64" ]
4159
4155
impl u64 {
4160
- uint_impl ! { u64 , u64 , 64 , 18446744073709551615 , "" , "" , 12 , "0xaa00000000006e1" , "0x6e10aa" }
4156
+ uint_impl ! { u64 , u64 , 64 , 18446744073709551615 , "" , "" , 12 , "0xaa00000000006e1" , "0x6e10aa" ,
4157
+ "0x1234567890123456" , "0x5634129078563412" , "0x6a2c48091e6a2c48" }
4161
4158
}
4162
4159
4163
4160
#[ lang = "u128" ]
4164
4161
impl u128 {
4165
4162
uint_impl ! { u128 , u128 , 128 , 340282366920938463463374607431768211455 , "" , "" , 16 ,
4166
- "0x13f40000000000000000000000004f76" , "0x4f7613f4" }
4163
+ "0x13f40000000000000000000000004f76" , "0x4f7613f4" , "0x12345678901234567890123456789012" ,
4164
+ "0x12907856341290785634129078563412" , "0x48091e6a2c48091e6a2c48091e6a2c48" }
4167
4165
}
4168
4166
4169
4167
#[ cfg( target_pointer_width = "16" ) ]
4170
4168
#[ lang = "usize" ]
4171
4169
impl usize {
4172
- uint_impl ! { usize , u16 , 16 , 65536 , "" , "" , 4 , "0xa003" , "0x3a" }
4170
+ uint_impl ! { usize , u16 , 16 , 65536 , "" , "" , 4 , "0xa003" , "0x3a" , "0x1234" , "0x3412" , "0x2c48" }
4173
4171
}
4174
4172
#[ cfg( target_pointer_width = "32" ) ]
4175
4173
#[ lang = "usize" ]
4176
4174
impl usize {
4177
- uint_impl ! { usize , u32 , 32 , 4294967295 , "" , "" , 8 , "0x10000b3" , "0xb301" }
4175
+ uint_impl ! { usize , u32 , 32 , 4294967295 , "" , "" , 8 , "0x10000b3" , "0xb301" , "0x12345678" ,
4176
+ "0x78563412" , "0x1e6a2c48" }
4178
4177
}
4179
4178
4180
4179
#[ cfg( target_pointer_width = "64" ) ]
4181
4180
#[ lang = "usize" ]
4182
4181
impl usize {
4183
- uint_impl ! { usize , u64 , 64 , 18446744073709551615 , "" , "" , 12 , "0xaa00000000006e1" ,
4184
- "0x6e10aa " }
4182
+ uint_impl ! { usize , u64 , 64 , 18446744073709551615 , "" , "" , 12 , "0xaa00000000006e1" , "0x6e10aa" ,
4183
+ "0x1234567890123456" , "0x5634129078563412" , "0x6a2c48091e6a2c48 " }
4185
4184
}
4186
4185
4187
4186
/// A classification of floating point numbers.
0 commit comments