#[repr(transparent)]pub struct Wrapping<T>(pub T);
Expand description
Provides intentionally-wrapped arithmetic on T
.
Operations like +
on u32
values are intended to never overflow,
and in some debug configurations overflow is detected and results
in a panic. While most arithmetic falls into this category, some
code explicitly expects and relies upon modular arithmetic (e.g.,
hashing).
Wrapping arithmetic can be achieved either through methods like
wrapping_add
, or through the Wrapping<T>
type, which says that
all standard arithmetic operations on the underlying value are
intended to have wrapping semantics.
The underlying value can be retrieved through the .0
index of the
Wrapping
tuple.
Examples
use std::num::Wrapping;
let zero = Wrapping(0u32);
let one = Wrapping(1u32);
assert_eq!(u32::MAX, (zero - one).0);
RunLayout
Wrapping<T>
is guaranteed to have the same layout and ABI as T
.
Tuple Fields
0: T
Implementations
sourceimpl Wrapping<usize>
impl Wrapping<usize>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ausize);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<usize>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<usize>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ausize);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<usize>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<usize>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ausize);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ausize);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3usize).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<u8>
impl Wrapping<u8>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au8);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<u8>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<u8>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au8);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<u8>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<u8>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au8);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au8);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3u8).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<u16>
impl Wrapping<u16>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au16);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<u16>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<u16>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au16);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<u16>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<u16>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au16);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au16);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3u16).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<u32>
impl Wrapping<u32>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au32);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<u32>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<u32>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au32);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<u32>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<u32>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au32);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au32);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3u32).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<u64>
impl Wrapping<u64>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au64);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<u64>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<u64>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au64);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<u64>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<u64>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au64);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au64);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3u64).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<u128>
impl Wrapping<u128>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au128);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<u128>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<u128>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au128);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<u128>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<u128>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au128);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au128);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3u128).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<isize>
impl Wrapping<isize>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Aisize);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<isize>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<isize>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Aisize);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<isize>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<isize>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Aisize);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Aisize);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3isize).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<i8>
impl Wrapping<i8>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai8);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<i8>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<i8>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai8);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<i8>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<i8>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai8);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai8);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<i16>
impl Wrapping<i16>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai16);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<i16>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<i16>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai16);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<i16>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<i16>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai16);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai16);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i16).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<i32>
impl Wrapping<i32>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai32);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<i32>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<i32>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai32);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<i32>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<i32>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai32);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai32);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i32).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<i64>
impl Wrapping<i64>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai64);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<i64>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<i64>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai64);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<i64>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<i64>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai64);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai64);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i64).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<i128>
impl Wrapping<i128>
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Runsourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Runsourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
Run1.37.0 (const: 1.37.0) · sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the bit pattern of the integer.
Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Runsourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai128);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<i128>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<i128>>::from_be(n), n.swap_bytes())
}
Runsourcepub const fn from_le(x: Self) -> Self
pub const fn from_le(x: Self) -> Self
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai128);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<i128>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<i128>>::from_le(n), n.swap_bytes())
}
Runsourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai128);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Runsourcepub const fn to_le(self) -> Self
pub const fn to_le(self) -> Self
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Ai128);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Runsourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power of exp
, using exponentiation by squaring.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i128).pow(4), Wrapping(81));
RunResults that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Runsourceimpl Wrapping<isize>
impl Wrapping<isize>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn abs(self) -> Wrapping<isize>
pub fn abs(self) -> Wrapping<isize>
Computes the absolute value of self
, wrapping around at
the boundary of the type.
The only case where such wrapping can occur is when one takes the absolute value of the negative
minimal value for the type this is a positive value that is too large to represent in the type. In
such a case, this function returns MIN
itself.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(100isize).abs(), Wrapping(100));
assert_eq!(Wrapping(-100isize).abs(), Wrapping(100));
assert_eq!(Wrapping(isize::MIN).abs(), Wrapping(isize::MIN));
assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
Runsourcepub fn signum(self) -> Wrapping<isize>
pub fn signum(self) -> Wrapping<isize>
Returns a number representing sign of self
.
0
if the number is zero1
if the number is positive-1
if the number is negative
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(10isize).signum(), Wrapping(1));
assert_eq!(Wrapping(0isize).signum(), Wrapping(0));
assert_eq!(Wrapping(-10isize).signum(), Wrapping(-1));
Runsourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
sourceimpl Wrapping<i8>
impl Wrapping<i8>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn abs(self) -> Wrapping<i8>
pub fn abs(self) -> Wrapping<i8>
Computes the absolute value of self
, wrapping around at
the boundary of the type.
The only case where such wrapping can occur is when one takes the absolute value of the negative
minimal value for the type this is a positive value that is too large to represent in the type. In
such a case, this function returns MIN
itself.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(100i8).abs(), Wrapping(100));
assert_eq!(Wrapping(-100i8).abs(), Wrapping(100));
assert_eq!(Wrapping(i8::MIN).abs(), Wrapping(i8::MIN));
assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
Runsourcepub fn signum(self) -> Wrapping<i8>
pub fn signum(self) -> Wrapping<i8>
Returns a number representing sign of self
.
0
if the number is zero1
if the number is positive-1
if the number is negative
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(10i8).signum(), Wrapping(1));
assert_eq!(Wrapping(0i8).signum(), Wrapping(0));
assert_eq!(Wrapping(-10i8).signum(), Wrapping(-1));
Runsourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
sourceimpl Wrapping<i16>
impl Wrapping<i16>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn abs(self) -> Wrapping<i16>
pub fn abs(self) -> Wrapping<i16>
Computes the absolute value of self
, wrapping around at
the boundary of the type.
The only case where such wrapping can occur is when one takes the absolute value of the negative
minimal value for the type this is a positive value that is too large to represent in the type. In
such a case, this function returns MIN
itself.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(100i16).abs(), Wrapping(100));
assert_eq!(Wrapping(-100i16).abs(), Wrapping(100));
assert_eq!(Wrapping(i16::MIN).abs(), Wrapping(i16::MIN));
assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
Runsourcepub fn signum(self) -> Wrapping<i16>
pub fn signum(self) -> Wrapping<i16>
Returns a number representing sign of self
.
0
if the number is zero1
if the number is positive-1
if the number is negative
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(10i16).signum(), Wrapping(1));
assert_eq!(Wrapping(0i16).signum(), Wrapping(0));
assert_eq!(Wrapping(-10i16).signum(), Wrapping(-1));
Runsourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
sourceimpl Wrapping<i32>
impl Wrapping<i32>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn abs(self) -> Wrapping<i32>
pub fn abs(self) -> Wrapping<i32>
Computes the absolute value of self
, wrapping around at
the boundary of the type.
The only case where such wrapping can occur is when one takes the absolute value of the negative
minimal value for the type this is a positive value that is too large to represent in the type. In
such a case, this function returns MIN
itself.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(100i32).abs(), Wrapping(100));
assert_eq!(Wrapping(-100i32).abs(), Wrapping(100));
assert_eq!(Wrapping(i32::MIN).abs(), Wrapping(i32::MIN));
assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
Runsourcepub fn signum(self) -> Wrapping<i32>
pub fn signum(self) -> Wrapping<i32>
Returns a number representing sign of self
.
0
if the number is zero1
if the number is positive-1
if the number is negative
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(10i32).signum(), Wrapping(1));
assert_eq!(Wrapping(0i32).signum(), Wrapping(0));
assert_eq!(Wrapping(-10i32).signum(), Wrapping(-1));
Runsourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
sourceimpl Wrapping<i64>
impl Wrapping<i64>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn abs(self) -> Wrapping<i64>
pub fn abs(self) -> Wrapping<i64>
Computes the absolute value of self
, wrapping around at
the boundary of the type.
The only case where such wrapping can occur is when one takes the absolute value of the negative
minimal value for the type this is a positive value that is too large to represent in the type. In
such a case, this function returns MIN
itself.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(100i64).abs(), Wrapping(100));
assert_eq!(Wrapping(-100i64).abs(), Wrapping(100));
assert_eq!(Wrapping(i64::MIN).abs(), Wrapping(i64::MIN));
assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
Runsourcepub fn signum(self) -> Wrapping<i64>
pub fn signum(self) -> Wrapping<i64>
Returns a number representing sign of self
.
0
if the number is zero1
if the number is positive-1
if the number is negative
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(10i64).signum(), Wrapping(1));
assert_eq!(Wrapping(0i64).signum(), Wrapping(0));
assert_eq!(Wrapping(-10i64).signum(), Wrapping(-1));
Runsourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
sourceimpl Wrapping<i128>
impl Wrapping<i128>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn abs(self) -> Wrapping<i128>
pub fn abs(self) -> Wrapping<i128>
Computes the absolute value of self
, wrapping around at
the boundary of the type.
The only case where such wrapping can occur is when one takes the absolute value of the negative
minimal value for the type this is a positive value that is too large to represent in the type. In
such a case, this function returns MIN
itself.
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(100i128).abs(), Wrapping(100));
assert_eq!(Wrapping(-100i128).abs(), Wrapping(100));
assert_eq!(Wrapping(i128::MIN).abs(), Wrapping(i128::MIN));
assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
Runsourcepub fn signum(self) -> Wrapping<i128>
pub fn signum(self) -> Wrapping<i128>
Returns a number representing sign of self
.
0
if the number is zero1
if the number is positive-1
if the number is negative
Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(10i128).signum(), Wrapping(1));
assert_eq!(Wrapping(0i128).signum(), Wrapping(0));
assert_eq!(Wrapping(-10i128).signum(), Wrapping(-1));
Runsourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
sourceimpl Wrapping<usize>
impl Wrapping<usize>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn is_power_of_two(self) -> bool
pub fn is_power_of_two(self) -> bool
sourcepub fn next_power_of_two(self) -> Self
pub fn next_power_of_two(self) -> Self
Returns the smallest power of two greater than or equal to self
.
When return value overflows (i.e., self > (1 << (N-1))
for type
uN
), overflows to 2^N = 0
.
Examples
Basic usage:
#![feature(wrapping_next_power_of_two)]
use std::num::Wrapping;
assert_eq!(Wrapping(2usize).next_power_of_two(), Wrapping(2));
assert_eq!(Wrapping(3usize).next_power_of_two(), Wrapping(4));
assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));
Runsourceimpl Wrapping<u8>
impl Wrapping<u8>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn is_power_of_two(self) -> bool
pub fn is_power_of_two(self) -> bool
sourcepub fn next_power_of_two(self) -> Self
pub fn next_power_of_two(self) -> Self
Returns the smallest power of two greater than or equal to self
.
When return value overflows (i.e., self > (1 << (N-1))
for type
uN
), overflows to 2^N = 0
.
Examples
Basic usage:
#![feature(wrapping_next_power_of_two)]
use std::num::Wrapping;
assert_eq!(Wrapping(2u8).next_power_of_two(), Wrapping(2));
assert_eq!(Wrapping(3u8).next_power_of_two(), Wrapping(4));
assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));
Runsourceimpl Wrapping<u16>
impl Wrapping<u16>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn is_power_of_two(self) -> bool
pub fn is_power_of_two(self) -> bool
sourcepub fn next_power_of_two(self) -> Self
pub fn next_power_of_two(self) -> Self
Returns the smallest power of two greater than or equal to self
.
When return value overflows (i.e., self > (1 << (N-1))
for type
uN
), overflows to 2^N = 0
.
Examples
Basic usage:
#![feature(wrapping_next_power_of_two)]
use std::num::Wrapping;
assert_eq!(Wrapping(2u16).next_power_of_two(), Wrapping(2));
assert_eq!(Wrapping(3u16).next_power_of_two(), Wrapping(4));
assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));
Runsourceimpl Wrapping<u32>
impl Wrapping<u32>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn is_power_of_two(self) -> bool
pub fn is_power_of_two(self) -> bool
sourcepub fn next_power_of_two(self) -> Self
pub fn next_power_of_two(self) -> Self
Returns the smallest power of two greater than or equal to self
.
When return value overflows (i.e., self > (1 << (N-1))
for type
uN
), overflows to 2^N = 0
.
Examples
Basic usage:
#![feature(wrapping_next_power_of_two)]
use std::num::Wrapping;
assert_eq!(Wrapping(2u32).next_power_of_two(), Wrapping(2));
assert_eq!(Wrapping(3u32).next_power_of_two(), Wrapping(4));
assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));
Runsourceimpl Wrapping<u64>
impl Wrapping<u64>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn is_power_of_two(self) -> bool
pub fn is_power_of_two(self) -> bool
sourcepub fn next_power_of_two(self) -> Self
pub fn next_power_of_two(self) -> Self
Returns the smallest power of two greater than or equal to self
.
When return value overflows (i.e., self > (1 << (N-1))
for type
uN
), overflows to 2^N = 0
.
Examples
Basic usage:
#![feature(wrapping_next_power_of_two)]
use std::num::Wrapping;
assert_eq!(Wrapping(2u64).next_power_of_two(), Wrapping(2));
assert_eq!(Wrapping(3u64).next_power_of_two(), Wrapping(4));
assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));
Runsourceimpl Wrapping<u128>
impl Wrapping<u128>
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
sourcepub fn is_power_of_two(self) -> bool
pub fn is_power_of_two(self) -> bool
sourcepub fn next_power_of_two(self) -> Self
pub fn next_power_of_two(self) -> Self
Returns the smallest power of two greater than or equal to self
.
When return value overflows (i.e., self > (1 << (N-1))
for type
uN
), overflows to 2^N = 0
.
Examples
Basic usage:
#![feature(wrapping_next_power_of_two)]
use std::num::Wrapping;
assert_eq!(Wrapping(2u128).next_power_of_two(), Wrapping(2));
assert_eq!(Wrapping(3u128).next_power_of_two(), Wrapping(4));
assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));
RunTrait Implementations
sourceimpl<T: Ord> Ord for Wrapping<T>
impl<T: Ord> Ord for Wrapping<T>
1.21.0 · sourcefn max(self, other: Self) -> Self where
Self: Sized,
fn max(self, other: Self) -> Self where
Self: Sized,
Compares and returns the maximum of two values. Read more
sourceimpl<T: PartialOrd> PartialOrd<Wrapping<T>> for Wrapping<T>
impl<T: PartialOrd> PartialOrd<Wrapping<T>> for Wrapping<T>
sourcefn partial_cmp(&self, other: &Wrapping<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &Wrapping<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<u8>
impl ShlAssign<&'_ usize> for Wrapping<u8>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<u16>
impl ShlAssign<&'_ usize> for Wrapping<u16>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<i128>
impl ShlAssign<&'_ usize> for Wrapping<i128>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<isize>
impl ShlAssign<&'_ usize> for Wrapping<isize>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<u32>
impl ShlAssign<&'_ usize> for Wrapping<u32>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<u64>
impl ShlAssign<&'_ usize> for Wrapping<u64>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<u128>
impl ShlAssign<&'_ usize> for Wrapping<u128>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<usize>
impl ShlAssign<&'_ usize> for Wrapping<usize>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<i8>
impl ShlAssign<&'_ usize> for Wrapping<i8>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<i16>
impl ShlAssign<&'_ usize> for Wrapping<i16>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<i32>
impl ShlAssign<&'_ usize> for Wrapping<i32>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShlAssign<&'_ usize> for Wrapping<i64>
impl ShlAssign<&'_ usize> for Wrapping<i64>
const: unstable · sourcefn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<u8>
impl ShlAssign<usize> for Wrapping<u8>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<u16>
impl ShlAssign<usize> for Wrapping<u16>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<i128>
impl ShlAssign<usize> for Wrapping<i128>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<isize>
impl ShlAssign<usize> for Wrapping<isize>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<u32>
impl ShlAssign<usize> for Wrapping<u32>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<u64>
impl ShlAssign<usize> for Wrapping<u64>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<u128>
impl ShlAssign<usize> for Wrapping<u128>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<usize>
impl ShlAssign<usize> for Wrapping<usize>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<i8>
impl ShlAssign<usize> for Wrapping<i8>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<i16>
impl ShlAssign<usize> for Wrapping<i16>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<i32>
impl ShlAssign<usize> for Wrapping<i32>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShlAssign<usize> for Wrapping<i64>
impl ShlAssign<usize> for Wrapping<i64>
const: unstable · sourcefn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
Performs the <<=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<u8>
impl ShrAssign<&'_ usize> for Wrapping<u8>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<u16>
impl ShrAssign<&'_ usize> for Wrapping<u16>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<i128>
impl ShrAssign<&'_ usize> for Wrapping<i128>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<isize>
impl ShrAssign<&'_ usize> for Wrapping<isize>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<u32>
impl ShrAssign<&'_ usize> for Wrapping<u32>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<u64>
impl ShrAssign<&'_ usize> for Wrapping<u64>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<u128>
impl ShrAssign<&'_ usize> for Wrapping<u128>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<usize>
impl ShrAssign<&'_ usize> for Wrapping<usize>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<i8>
impl ShrAssign<&'_ usize> for Wrapping<i8>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<i16>
impl ShrAssign<&'_ usize> for Wrapping<i16>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<i32>
impl ShrAssign<&'_ usize> for Wrapping<i32>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.22.0 (const: unstable) · sourceimpl ShrAssign<&'_ usize> for Wrapping<i64>
impl ShrAssign<&'_ usize> for Wrapping<i64>
const: unstable · sourcefn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<u8>
impl ShrAssign<usize> for Wrapping<u8>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<u16>
impl ShrAssign<usize> for Wrapping<u16>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<i128>
impl ShrAssign<usize> for Wrapping<i128>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<isize>
impl ShrAssign<usize> for Wrapping<isize>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<u32>
impl ShrAssign<usize> for Wrapping<u32>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<u64>
impl ShrAssign<usize> for Wrapping<u64>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<u128>
impl ShrAssign<usize> for Wrapping<u128>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<usize>
impl ShrAssign<usize> for Wrapping<usize>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<i8>
impl ShrAssign<usize> for Wrapping<i8>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<i16>
impl ShrAssign<usize> for Wrapping<i16>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<i32>
impl ShrAssign<usize> for Wrapping<i32>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
1.8.0 (const: unstable) · sourceimpl ShrAssign<usize> for Wrapping<i64>
impl ShrAssign<usize> for Wrapping<i64>
const: unstable · sourcefn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
Performs the >>=
operation. Read more
impl<T: Copy> Copy for Wrapping<T>
impl<T: Eq> Eq for Wrapping<T>
impl<T> StructuralEq for Wrapping<T>
impl<T> StructuralPartialEq for Wrapping<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Wrapping<T> where
T: RefUnwindSafe,
impl<T> Send for Wrapping<T> where
T: Send,
impl<T> Sync for Wrapping<T> where
T: Sync,
impl<T> Unpin for Wrapping<T> where
T: Unpin,
impl<T> UnwindSafe for Wrapping<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more