pub type BitUsize<const N: u32> = BitUint<usize, N>;
Expand description
A specialized BitUint
type whose the underlying type is restricted to
usize
.
The largest size of N
is equal to usize::BITS
.
Aliased Type§
struct BitUsize<const N: u32>(/* private fields */);
Implementations
Source§impl<T: Unsigned + PrimInt, const N: u32> BitUint<T, N>
impl<T: Unsigned + PrimInt, const N: u32> BitUint<T, N>
Sourcepub const unsafe fn new_unchecked(n: T) -> Self
pub const unsafe fn new_unchecked(n: T) -> Self
Creates a new BitUint
with the given unsigned integer value.
This method does not check whether the value is a valid N
-bit unsigned
integer. This results in undefined behaviour if the value is not a valid
N
-bit unsigned integer.
§Safety
The value must be a valid N
-bit unsigned integer.
Source§impl<const N: u32> BitUint<usize, N>
impl<const N: u32> BitUint<usize, N>
Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this BitUint
.
The value is always 0
.
§Examples
assert_eq!(BitUint::<usize, 7>::MIN.get(), 0);
Source§impl<const N: u32> BitUint<usize, N>
impl<const N: u32> BitUint<usize, N>
Sourcepub const fn checked_add(self, rhs: usize) -> Option<Self>
pub const fn checked_add(self, rhs: usize) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: usize) -> Option<Self>
pub const fn checked_sub(self, rhs: usize) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: usize) -> Option<Self>
pub const fn checked_mul(self, rhs: usize) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: usize) -> Option<Self>
pub const fn checked_div(self, rhs: usize) -> Option<Self>
Sourcepub const fn checked_div_euclid(self, rhs: usize) -> Option<Self>
pub const fn checked_div_euclid(self, rhs: usize) -> Option<Self>
Sourcepub const fn checked_rem(self, rhs: usize) -> Option<Self>
pub const fn checked_rem(self, rhs: usize) -> Option<Self>
Sourcepub const fn checked_rem_euclid(self, rhs: usize) -> Option<Self>
pub const fn checked_rem_euclid(self, rhs: usize) -> Option<Self>
Sourcepub const fn checked_ilog(self, base: usize) -> Option<u32>
pub const fn checked_ilog(self, base: usize) -> Option<u32>
Sourcepub const fn checked_ilog2(self) -> Option<u32>
pub const fn checked_ilog2(self) -> Option<u32>
Sourcepub const fn checked_ilog10(self) -> Option<u32>
pub const fn checked_ilog10(self) -> Option<u32>
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Shifts self
left by rhs
bits.
Returns None
if rhs
is larger than or equal to the number of bits
in self
.
§Examples
let n = BitUint::<usize, 5>::new(0x01).unwrap();
let m = BitUint::<usize, 5>::new(0x10).unwrap();
assert_eq!(n.checked_shl(4).map(BitUint::get), Some(0x10));
assert_eq!(m.checked_shl(129), None);
assert_eq!(m.checked_shl(usize::BITS - 1).map(BitUint::get), Some(0x00));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn checked_pow(self, exp: u32) -> Option<Self>
pub const fn checked_pow(self, exp: u32) -> Option<Self>
Trait Implementations
Source§impl<T: Ord + Unsigned + PrimInt, const N: u32> Ord for BitUint<T, N>
impl<T: Ord + Unsigned + PrimInt, const N: u32> Ord for BitUint<T, N>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more