#[repr(transparent)]pub struct U7(_);
Expand description
The 7-bit unsigned bitint
type.
Layout
This type is #[repr(transparent)]
to u8
, but imposes additional invariants.
Invariants
The value is represented in the least significant bits of a u8
. The unused most significant bits are always clear.
Implementations§
source§impl U7
impl U7
sourcepub const BITS: u32 = 7u32
pub const BITS: u32 = 7u32
The bit width of this type.
See also: UBitint::BITS
sourcepub const MASK: u8 = 127u8
pub const MASK: u8 = 127u8
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: u8) -> Option<Self>
pub const fn new(value: u8) -> 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: u8) -> Self
pub const fn new_masked(value: u8) -> 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: u8) -> Self
pub const unsafe fn new_unchecked(value: u8) -> 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) -> u8
pub const fn to_primitive(self) -> u8
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: u8) -> bool
pub const fn is_in_range(value: u8) -> 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<U7> for U7
impl AddAssign<U7> for U7
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresource§impl BitAndAssign<U7> for U7
impl BitAndAssign<U7> for U7
source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&=
operation. Read moresource§impl BitOrAssign<U7> for U7
impl BitOrAssign<U7> for U7
source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read moresource§impl BitXorAssign<U7> for U7
impl BitXorAssign<U7> for U7
source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^=
operation. Read moresource§impl CheckedAdd for U7
impl CheckedAdd for U7
source§fn checked_add(&self, v: &Self) -> Option<Self>
fn checked_add(&self, v: &Self) -> Option<Self>
None
is
returned.source§impl CheckedDiv for U7
impl CheckedDiv for U7
source§fn checked_div(&self, v: &Self) -> Option<Self>
fn checked_div(&self, v: &Self) -> Option<Self>
None
is returned.source§impl CheckedMul for U7
impl CheckedMul for U7
source§fn checked_mul(&self, v: &Self) -> Option<Self>
fn checked_mul(&self, v: &Self) -> Option<Self>
None
is returned.source§impl CheckedRem for U7
impl CheckedRem for U7
source§impl CheckedSub for U7
impl CheckedSub for U7
source§fn checked_sub(&self, v: &Self) -> Option<Self>
fn checked_sub(&self, v: &Self) -> Option<Self>
None
is returned.source§impl DivAssign<U7> for U7
impl DivAssign<U7> for U7
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moresource§impl FromStr for U7
impl FromStr for U7
§type Err = ParseBitintError
type Err = ParseBitintError
source§impl MulAssign<U7> for U7
impl MulAssign<U7> for U7
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresource§impl Num for U7
impl Num for U7
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 U7
impl Ord for U7
source§impl PartialEq<U7> for U7
impl PartialEq<U7> for U7
source§impl PartialOrd<U7> for U7
impl PartialOrd<U7> for U7
source§impl RemAssign<U7> for U7
impl RemAssign<U7> for U7
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%=
operation. Read moresource§impl SubAssign<U7> for U7
impl SubAssign<U7> for U7
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moresource§impl TryFrom<u8> for U7
impl TryFrom<u8> for U7
§type Error = RangeError
type Error = RangeError
source§impl UBitint for U7
impl UBitint for U7
source§fn new(value: u8) -> Option<Self>
fn new(value: u8) -> 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: u8) -> Self
fn new_masked(value: u8) -> Self
bitint
value by masking off the upper bits of a
primitive value. Read moresource§unsafe fn new_unchecked(value: u8) -> Self
unsafe fn new_unchecked(value: u8) -> Self
bitint
value from a primitive value without
checking whether it is in range for this type. Read moresource§impl WrappingAdd for U7
impl WrappingAdd for U7
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 U7
impl WrappingMul for U7
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 U7
impl WrappingSub for U7
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.