pub struct NonMaxU8(/* private fields */);Expand description
Implementations§
Source§impl NonMaxU8
impl NonMaxU8
Sourcepub const BITS_UNDERLYING: u32 = 8u32
pub const BITS_UNDERLYING: u32 = 8u32
Sourcepub const INVALID_UNDERLYING: u8 = 255u8
pub const INVALID_UNDERLYING: u8 = 255u8
The value of the underlying integer that can not be represented
Sourcepub const MAX_UNDERLYING: u8 = 254u8
pub const MAX_UNDERLYING: u8 = 254u8
The maximum value that can be safely converted into Self
Sourcepub const fn new(value: u8) -> Option<Self>
pub const fn new(value: u8) -> Option<Self>
Create a new Self or None if value is the max of the underlying integer type
Sourcepub const unsafe fn new_unchecked(value: u8) -> Self
pub const unsafe fn new_unchecked(value: u8) -> Self
Sourcepub const fn get(self) -> u8
pub const fn get(self) -> u8
Return the underlying integer type
The result is a native-endian integer
Sourcepub const fn abs_diff(self, other: Self) -> Self
pub const fn abs_diff(self, other: Self) -> Self
Computes the absolute difference between self and other.
Sourcepub const fn div_ceil(self, other: Self) -> Self
pub const fn div_ceil(self, other: Self) -> Self
Calculates the quotient of self and rhs, rounding the result towards positive infinity.
Sourcepub const fn is_multiple_of(self, rhs: Self) -> bool
pub const fn is_multiple_of(self, rhs: Self) -> bool
Returns true if self is an integer multiple of rhs, and false otherwise.
This function is equivalent to self % rhs == 0, except that it will not panic for rhs == 0.
Instead, 0.is_multiple_of(0) == true, and for any non-zero n, n.is_multiple_of(0) == false.
Sourcepub const fn is_power_of_two(self) -> bool
pub const fn is_power_of_two(self) -> bool
Returns true if and only if self == 2^k for some unsigned integer k.
Sourcepub const fn checked_next_power_of_two(self) -> Option<Self>
pub const fn checked_next_power_of_two(self) -> Option<Self>
Returns the smallest power of two greater than or equal to self. If the next power of two is
greater than the type’s maximum value, None is returned, otherwise the power of two is wrapped in Some.
Sourcepub const fn checked_next_multiple_of(self, other: Self) -> Option<Self>
pub const fn checked_next_multiple_of(self, other: Self) -> Option<Self>
Calculates the smallest value greater than or equal to self that is a multiple of rhs. Returns None if rhs is zero or the operation would result in overflow.
Sourcepub const fn midpoint(self, other: Self) -> Self
pub const fn midpoint(self, other: Self) -> Self
Calculates the midpoint (average) between self and rhs.
midpoint(a, b) is (a + b) / 2 as if it were performed in a sufficiently-large unsigned integral type.
This implies that the result is always rounded towards zero and that no overflow will ever occur.
Sourcepub const fn ilog(self, base: Self) -> u32
pub const fn ilog(self, base: Self) -> u32
Returns the logarithm of the number with respect to an arbitrary base, rounded down.
This method might not be optimized owing to implementation details;
ilog2 can produce results more efficiently for base 2, and ilog10 can produce results more efficiently for base 10.
§Panics
This function will panic if self is zero, or if base is less than 2.
Sourcepub const fn ilog2(self) -> u32
pub const fn ilog2(self) -> u32
Returns the base 2 logarithm of the number, rounded down.
§Panics
This function will panic if self is zero.
Sourcepub const fn ilog10(self) -> u32
pub const fn ilog10(self) -> u32
Returns the base 10 logarithm of the number, rounded down.
§Panics
This function will panic if self is zero.
Sourcepub const fn checked_add(self, rhs: NonMaxU8) -> Option<NonMaxU8>
pub const fn checked_add(self, rhs: NonMaxU8) -> Option<NonMaxU8>
Checked integer addition. Computes self + rhs, returning None if overflow occured.
Sourcepub const fn checked_sub(self, rhs: NonMaxU8) -> Option<NonMaxU8>
pub const fn checked_sub(self, rhs: NonMaxU8) -> Option<NonMaxU8>
Checked integer subtraction. Computes self - rhs, returning None if overflow occured.
Sourcepub const fn checked_mul(self, rhs: NonMaxU8) -> Option<NonMaxU8>
pub const fn checked_mul(self, rhs: NonMaxU8) -> Option<NonMaxU8>
Checked integer multiplication. Computes self * rhs, returning None if overflow occured.
Sourcepub const fn checked_div(self, rhs: NonMaxU8) -> Option<NonMaxU8>
pub const fn checked_div(self, rhs: NonMaxU8) -> Option<NonMaxU8>
Checked integer division. Computes self / rhs, returning None if rhs == 0.
Sourcepub const fn checked_div_euclid(self, rhs: NonMaxU8) -> Option<NonMaxU8>
pub const fn checked_div_euclid(self, rhs: NonMaxU8) -> Option<NonMaxU8>
Checked Euclidean division. Computes self.div_euclid(rhs), returning None if rhs == 0.
Strict division on unsigned types is just normal division. There’s no way overflow could ever happen. This function exists so that all operations are accounted for in the strict operations. Since, for the positive integers, all common definitions of division are equal, this is exactly equal to self.strict_div(rhs).
Sourcepub const fn checked_rem(self, rhs: NonMaxU8) -> Option<NonMaxU8>
pub const fn checked_rem(self, rhs: NonMaxU8) -> Option<NonMaxU8>
Checked integer division. Computes self % rhs, returning None if rhs == 0.
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<NonMaxU8>
pub const fn checked_shl(self, rhs: u32) -> Option<NonMaxU8>
Checked integer division. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self.
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<NonMaxU8>
pub const fn checked_shr(self, rhs: u32) -> Option<NonMaxU8>
Checked integer division. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self.
Sourcepub const fn checked_ilog(self, base: NonMaxU8) -> Option<u32>
pub const fn checked_ilog(self, base: NonMaxU8) -> Option<u32>
Returns the logarithm of the number with respect to an arbitrary base, rounded down.
Returns None if the number is zero, or if the base is not at least 2.
This method might not be optimized owing to implementation details;
checked_ilog2 can produce results more efficiently for base 2, and checked_ilog10 can produce results more efficiently for base 10.
Sourcepub const fn checked_ilog2(self) -> Option<u32>
pub const fn checked_ilog2(self) -> Option<u32>
Returns the base 2 logarithm of the number, rounded down.
Returns None if the number is zero.
Sourcepub const fn checked_ilog10(self) -> Option<u32>
pub const fn checked_ilog10(self) -> Option<u32>
Returns the base 10 logarithm of the number, rounded down.
Returns None if the number is zero.
Trait Implementations§
Source§impl AddAssign<&NonMaxU8> for NonMaxU8
impl AddAssign<&NonMaxU8> for NonMaxU8
Source§fn add_assign(&mut self, other: &NonMaxU8)
fn add_assign(&mut self, other: &NonMaxU8)
+= operation. Read moreSource§impl AddAssign<&u8> for NonMaxU8
impl AddAssign<&u8> for NonMaxU8
Source§fn add_assign(&mut self, other: &u8)
fn add_assign(&mut self, other: &u8)
+= operation. Read moreSource§impl AddAssign<u8> for NonMaxU8
impl AddAssign<u8> for NonMaxU8
Source§fn add_assign(&mut self, other: u8)
fn add_assign(&mut self, other: u8)
+= operation. Read moreSource§impl AddAssign for NonMaxU8
impl AddAssign for NonMaxU8
Source§fn add_assign(&mut self, other: NonMaxU8)
fn add_assign(&mut self, other: NonMaxU8)
+= operation. Read moreSource§impl BitAndAssign<&NonMaxU8> for NonMaxU8
impl BitAndAssign<&NonMaxU8> for NonMaxU8
Source§fn bitand_assign(&mut self, other: &NonMaxU8)
fn bitand_assign(&mut self, other: &NonMaxU8)
&= operation. Read moreSource§impl BitAndAssign<&u8> for NonMaxU8
impl BitAndAssign<&u8> for NonMaxU8
Source§fn bitand_assign(&mut self, other: &u8)
fn bitand_assign(&mut self, other: &u8)
&= operation. Read moreSource§impl BitAndAssign<u8> for NonMaxU8
impl BitAndAssign<u8> for NonMaxU8
Source§fn bitand_assign(&mut self, other: u8)
fn bitand_assign(&mut self, other: u8)
&= operation. Read moreSource§impl BitAndAssign for NonMaxU8
impl BitAndAssign for NonMaxU8
Source§fn bitand_assign(&mut self, other: NonMaxU8)
fn bitand_assign(&mut self, other: NonMaxU8)
&= operation. Read moreSource§impl BitOrAssign<&NonMaxU8> for NonMaxU8
impl BitOrAssign<&NonMaxU8> for NonMaxU8
Source§fn bitor_assign(&mut self, other: &NonMaxU8)
fn bitor_assign(&mut self, other: &NonMaxU8)
|= operation. Read moreSource§impl BitOrAssign<&u8> for NonMaxU8
impl BitOrAssign<&u8> for NonMaxU8
Source§fn bitor_assign(&mut self, other: &u8)
fn bitor_assign(&mut self, other: &u8)
|= operation. Read moreSource§impl BitOrAssign<u8> for NonMaxU8
impl BitOrAssign<u8> for NonMaxU8
Source§fn bitor_assign(&mut self, other: u8)
fn bitor_assign(&mut self, other: u8)
|= operation. Read moreSource§impl BitOrAssign for NonMaxU8
impl BitOrAssign for NonMaxU8
Source§fn bitor_assign(&mut self, other: NonMaxU8)
fn bitor_assign(&mut self, other: NonMaxU8)
|= operation. Read moreSource§impl BitXorAssign<&NonMaxU8> for NonMaxU8
impl BitXorAssign<&NonMaxU8> for NonMaxU8
Source§fn bitxor_assign(&mut self, other: &NonMaxU8)
fn bitxor_assign(&mut self, other: &NonMaxU8)
^= operation. Read moreSource§impl BitXorAssign<&u8> for NonMaxU8
impl BitXorAssign<&u8> for NonMaxU8
Source§fn bitxor_assign(&mut self, other: &u8)
fn bitxor_assign(&mut self, other: &u8)
^= operation. Read moreSource§impl BitXorAssign<u8> for NonMaxU8
impl BitXorAssign<u8> for NonMaxU8
Source§fn bitxor_assign(&mut self, other: u8)
fn bitxor_assign(&mut self, other: u8)
^= operation. Read moreSource§impl BitXorAssign for NonMaxU8
impl BitXorAssign for NonMaxU8
Source§fn bitxor_assign(&mut self, other: NonMaxU8)
fn bitxor_assign(&mut self, other: NonMaxU8)
^= operation. Read moreSource§impl DivAssign<&NonMaxU8> for NonMaxU8
impl DivAssign<&NonMaxU8> for NonMaxU8
Source§fn div_assign(&mut self, other: &NonMaxU8)
fn div_assign(&mut self, other: &NonMaxU8)
/= operation. Read moreSource§impl DivAssign<&u8> for NonMaxU8
impl DivAssign<&u8> for NonMaxU8
Source§fn div_assign(&mut self, other: &u8)
fn div_assign(&mut self, other: &u8)
/= operation. Read moreSource§impl DivAssign<u8> for NonMaxU8
impl DivAssign<u8> for NonMaxU8
Source§fn div_assign(&mut self, other: u8)
fn div_assign(&mut self, other: u8)
/= operation. Read moreSource§impl DivAssign for NonMaxU8
impl DivAssign for NonMaxU8
Source§fn div_assign(&mut self, other: NonMaxU8)
fn div_assign(&mut self, other: NonMaxU8)
/= operation. Read moreSource§impl MulAssign<&NonMaxU8> for NonMaxU8
impl MulAssign<&NonMaxU8> for NonMaxU8
Source§fn mul_assign(&mut self, other: &NonMaxU8)
fn mul_assign(&mut self, other: &NonMaxU8)
*= operation. Read moreSource§impl MulAssign<&u8> for NonMaxU8
impl MulAssign<&u8> for NonMaxU8
Source§fn mul_assign(&mut self, other: &u8)
fn mul_assign(&mut self, other: &u8)
*= operation. Read moreSource§impl MulAssign<u8> for NonMaxU8
impl MulAssign<u8> for NonMaxU8
Source§fn mul_assign(&mut self, other: u8)
fn mul_assign(&mut self, other: u8)
*= operation. Read moreSource§impl MulAssign for NonMaxU8
impl MulAssign for NonMaxU8
Source§fn mul_assign(&mut self, other: NonMaxU8)
fn mul_assign(&mut self, other: NonMaxU8)
*= operation. Read moreSource§impl Ord for NonMaxU8
impl Ord for NonMaxU8
Source§impl PartialOrd for NonMaxU8
impl PartialOrd for NonMaxU8
Source§impl SubAssign<&NonMaxU8> for NonMaxU8
impl SubAssign<&NonMaxU8> for NonMaxU8
Source§fn sub_assign(&mut self, other: &NonMaxU8)
fn sub_assign(&mut self, other: &NonMaxU8)
-= operation. Read moreSource§impl SubAssign<&u8> for NonMaxU8
impl SubAssign<&u8> for NonMaxU8
Source§fn sub_assign(&mut self, other: &u8)
fn sub_assign(&mut self, other: &u8)
-= operation. Read moreSource§impl SubAssign<u8> for NonMaxU8
impl SubAssign<u8> for NonMaxU8
Source§fn sub_assign(&mut self, other: u8)
fn sub_assign(&mut self, other: u8)
-= operation. Read moreSource§impl SubAssign for NonMaxU8
impl SubAssign for NonMaxU8
Source§fn sub_assign(&mut self, other: NonMaxU8)
fn sub_assign(&mut self, other: NonMaxU8)
-= operation. Read more