#[repr(transparent)]pub struct U40(_);
Expand description
The 40-bit unsigned bitint
type.
Layout
This type is #[repr(transparent)]
to u64
, but imposes additional invariants.
Invariants
The value is represented in the least significant bits of a u64
. The unused most significant bits are always clear.
Implementations§
source§impl U40
impl U40
sourcepub const BITS: u32 = 40u32
pub const BITS: u32 = 40u32
The bit width of this type.
See also: UBitint::BITS
sourcepub const MASK: u64 = 1_099_511_627_775u64
pub const MASK: u64 = 1_099_511_627_775u64
The bit mask for the bits that may be set in values of this type.
See also: UBitint::MASK
sourcepub const MIN: Self = _
pub const MIN: Self = _
The smallest value of this type.
See also: UBitint::MIN
sourcepub const MAX: Self = _
pub const MAX: Self = _
The largest value of this type.
See also: UBitint::MAX
sourcepub const ZERO: Self = _
pub const ZERO: Self = _
The value 0
represented in this type.
See also: UBitint::ZERO
, num_traits::Zero
sourcepub const ONE: Self = _
pub const ONE: Self = _
The value 1
represented in this type.
See also: UBitint::ONE
, num_traits::One
sourcepub const fn new(value: u64) -> Option<Self>
pub const fn new(value: u64) -> Option<Self>
Creates a bitint
from a primitive value if it is in range for
this type, as determined by is_in_range
.
This method is a const
variant of UBitint::new
.
sourcepub const fn new_masked(value: u64) -> Self
pub const fn new_masked(value: u64) -> Self
Creates a bitint
by masking off the upper bits of a primitive
value.
This conversion is lossless if the value is in range for this
type, as determined by is_in_range
.
This method is a const
variant of UBitint::new_masked
.
sourcepub const unsafe fn new_unchecked(value: u64) -> Self
pub const unsafe fn new_unchecked(value: u64) -> Self
Creates a bitint
from a primitive value without checking
whether it is in range for this type.
Safety
The value must be in range for this type, as determined by
is_in_range
.
This method is a const
variant of UBitint::new_unchecked
.
sourcepub const fn to_primitive(self) -> u64
pub const fn to_primitive(self) -> u64
Converts the value to a primitive type.
The result is in range for this type, as determined by
is_in_range
.
sourcepub const fn is_in_range(value: u64) -> bool
pub const fn is_in_range(value: u64) -> bool
Checks whether a primitive value is in range for this type.
There are a few equivalent ways to express this check.
- The unused most significant bits are clear:
(value & !Self::MASK) == 0
- The value is between
MIN
andMAX
, inclusive:value >= Self::MIN.as_primitive() && value <= Self::MAX.as_primitive()
This method is a const
variant of UBitint::is_in_range
.
sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Checked integer addition. Computes self + rhs
, returning None
if overflow occurred.
sourcepub const unsafe fn unchecked_add(self, rhs: Self) -> Self
Available on unchecked_math
only.
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self
unchecked_math
only.Unchecked integer addition. Computes self + rhs
, assuming overflow cannot occur.
Safety
The result must be in range for this type, as determined by is_in_range
.
sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Checked integer subtraction. Computes self - rhs
, returning None
if overflow occurred.
sourcepub const unsafe fn unchecked_sub(self, rhs: Self) -> Self
Available on unchecked_math
only.
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self
unchecked_math
only.Unchecked integer subtraction. Computes self - rhs
, assuming overflow cannot occur.
Safety
The result must be in range for this type, as determined by is_in_range
.
sourcepub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
Checked integer multiplication. Computes self * rhs
, returning None
if overflow occurred.
sourcepub const unsafe fn unchecked_mul(self, rhs: Self) -> Self
Available on unchecked_math
only.
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self
unchecked_math
only.Unchecked integer multiplication. Computes self * rhs
, assuming overflow cannot occur.
Safety
The result must be in range for this type, as determined by is_in_range
.
sourcepub const fn checked_div(self, rhs: Self) -> Option<Self>
pub const fn checked_div(self, rhs: Self) -> Option<Self>
Checked integer division. Computes self / rhs
, returning None
if rhs == 0
.
sourcepub const fn checked_rem(self, rhs: Self) -> Option<Self>
pub const fn checked_rem(self, rhs: Self) -> Option<Self>
Checked integer remainder. Computes self % rhs
, returning None
if rhs == 0
.
sourcepub const fn wrapping_add(self, rhs: Self) -> Self
pub const fn wrapping_add(self, rhs: Self) -> Self
Wrapping (modular) addition. Computes self + rhs
, wrapping around at the boundary of the type.
sourcepub const fn wrapping_sub(self, rhs: Self) -> Self
pub const fn wrapping_sub(self, rhs: Self) -> Self
Wrapping (modular) subtraction. Computes self - rhs
, wrapping around at the boundary of the type.
sourcepub const fn wrapping_mul(self, rhs: Self) -> Self
pub const fn wrapping_mul(self, rhs: Self) -> Self
Wrapping (modular) multiplication. Computes self * rhs
, wrapping around at the boundary of the type.
Trait Implementations§
source§impl AddAssign<U40> for U40
impl AddAssign<U40> for U40
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresource§impl BitAndAssign<U40> for U40
impl BitAndAssign<U40> for U40
source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&=
operation. Read moresource§impl BitOrAssign<U40> for U40
impl BitOrAssign<U40> for U40
source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read moresource§impl BitXorAssign<U40> for U40
impl BitXorAssign<U40> for U40
source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^=
operation. Read moresource§impl CheckedAdd for U40
impl CheckedAdd for U40
source§fn checked_add(&self, v: &Self) -> Option<Self>
fn checked_add(&self, v: &Self) -> Option<Self>
None
is
returned.source§impl CheckedDiv for U40
impl CheckedDiv for U40
source§fn checked_div(&self, v: &Self) -> Option<Self>
fn checked_div(&self, v: &Self) -> Option<Self>
None
is returned.source§impl CheckedMul for U40
impl CheckedMul for U40
source§fn checked_mul(&self, v: &Self) -> Option<Self>
fn checked_mul(&self, v: &Self) -> Option<Self>
None
is returned.source§impl CheckedRem for U40
impl CheckedRem for U40
source§impl CheckedSub for U40
impl CheckedSub for U40
source§fn checked_sub(&self, v: &Self) -> Option<Self>
fn checked_sub(&self, v: &Self) -> Option<Self>
None
is returned.source§impl DivAssign<U40> for U40
impl DivAssign<U40> for U40
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moresource§impl FromStr for U40
impl FromStr for U40
§type Err = ParseBitintError
type Err = ParseBitintError
source§impl MulAssign<U40> for U40
impl MulAssign<U40> for U40
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresource§impl Num for U40
impl Num for U40
type FromStrRadixErr = ParseBitintError
source§fn from_str_radix(str: &str, radix: u32) -> Result<Self, ParseBitintError>
fn from_str_radix(str: &str, radix: u32) -> Result<Self, ParseBitintError>
2..=36
). Read moresource§impl Ord for U40
impl Ord for U40
source§impl PartialEq<U40> for U40
impl PartialEq<U40> for U40
source§impl PartialOrd<U40> for U40
impl PartialOrd<U40> for U40
source§impl RemAssign<U40> for U40
impl RemAssign<U40> for U40
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%=
operation. Read moresource§impl SubAssign<U40> for U40
impl SubAssign<U40> for U40
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moresource§impl TryFrom<u64> for U40
impl TryFrom<u64> for U40
§type Error = RangeError
type Error = RangeError
source§impl UBitint for U40
impl UBitint for U40
source§const MASK: u64 = 1_099_511_627_775u64
const MASK: u64 = 1_099_511_627_775u64
source§fn new(value: u64) -> Option<Self>
fn new(value: u64) -> Option<Self>
bitint
value from a primitive value if it is in
range for this type, as determined by
is_in_range
.source§fn new_masked(value: u64) -> Self
fn new_masked(value: u64) -> Self
bitint
value by masking off the upper bits of a
primitive value. Read moresource§unsafe fn new_unchecked(value: u64) -> Self
unsafe fn new_unchecked(value: u64) -> Self
bitint
value from a primitive value without
checking whether it is in range for this type. Read moresource§impl WrappingAdd for U40
impl WrappingAdd for U40
source§fn wrapping_add(&self, v: &Self) -> Self
fn wrapping_add(&self, v: &Self) -> Self
self + other
, wrapping around at the boundary of
the type.source§impl WrappingMul for U40
impl WrappingMul for U40
source§fn wrapping_mul(&self, v: &Self) -> Self
fn wrapping_mul(&self, v: &Self) -> Self
self * other
, wrapping around at the boundary
of the type.source§impl WrappingSub for U40
impl WrappingSub for U40
source§fn wrapping_sub(&self, v: &Self) -> Self
fn wrapping_sub(&self, v: &Self) -> Self
self - other
, wrapping around at the boundary
of the type.