#[repr(C, align(8))]pub struct PositiveIsize { /* private fields */ }Expand description
A signed value that is known to be positive.
This enables some memory layout optimization.
For example, Option<PositiveIsize> is the same size as isize.
Implementations§
Source§impl PositiveIsize
impl PositiveIsize
Sourcepub const BITS: u32 = 64u32
pub const BITS: u32 = 64u32
The size of this positive integer type in bits.
This value is equal to isize::BITS.
Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this positive integer type, 0.
Sourcepub const MAX: Self
pub const MAX: Self
The largest value that can be represented by this positive integer type, equal to isize::MAX.
Sourcepub const fn new(value: isize) -> Option<Self>
pub const fn new(value: isize) -> Option<Self>
Creates a PositiveIsize if the given value is positive.
Sourcepub const unsafe fn new_unchecked(value: isize) -> Self
pub const unsafe fn new_unchecked(value: isize) -> Self
Creates a PositiveIsize without checking whether the value is positive.
This results in undefined behaviour if the value is negative.
§Safety
The value must not be negative.
Sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
Returns the number of zeros in the binary representation of self.
Sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
Returns the number of ones in the binary representation of self.
Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation of self.
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 == (1 << k) for some k.
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_neg(self) -> Option<NegativeIsize>
pub const fn checked_neg(self) -> Option<NegativeIsize>
Checked negation. Computes -self, returning None if self == 0.
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Checked addition. Adds a positive integer to another positive integer.
Checks for overflow and returns None on overflow.
As a consequence, the result cannot wrap to a negative integer.
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Checked subtraction. Subtracts a positive integer from another positive integer.
Returns None if the result would overflow into a negative integer.
Sourcepub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
Checked multiplication.
Multiplies a positive integer by another positive integer, returning a positive result.
Returns None if the result would overflow.
Sourcepub const fn checked_div(self, rhs: Self) -> Option<Self>
pub const fn checked_div(self, rhs: Self) -> Option<Self>
Checked division.
Divides a positive integer by another positive integer, returning the positive quotient.
Returns 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 remainder.
Divides a positive integer by another positive integer, returning the positive
remainder.
Returns None if rhs == 0.
Sourcepub const fn checked_div_unsigned(self, rhs: usize) -> Option<Self>
pub const fn checked_div_unsigned(self, rhs: usize) -> Option<Self>
Checked division by unsigned.
Divides a positive integer by an unsigned integer, returning the positive quotient.
Returns None if rhs == 0.
Sourcepub const fn checked_rem_unsigned(self, rhs: usize) -> Option<Self>
pub const fn checked_rem_unsigned(self, rhs: usize) -> Option<Self>
Checked remainder of unsigned.
Divides a positive integer by an unsigned integer, returning the positive remainder.
Returns None if rhs == 0.
Sourcepub const fn checked_pow(self, rhs: u32) -> Option<Self>
pub const fn checked_pow(self, rhs: u32) -> Option<Self>
Checked integer exponentiation.
Raises positive value to an integer power.
Checks for overflow and returns None on overflow.
As a consequence, the result cannot wrap to a negative integer.
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.
Checks for overflow and returns None
if the next power of two is greater than the type’s maximum value.
As a consequence, the result cannot wrap to a negative integer.
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.
Sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Saturating addition. Adds a positive integer to another positive integer.
Returns PositiveIsize::MAX on overflow.
Sourcepub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
Saturating subtraction. Subtracts a positive integer from another positive integer. Returns 0 if the result would overflow into a negative integer.
Sourcepub const fn saturating_mul(self, rhs: Self) -> Self
pub const fn saturating_mul(self, rhs: Self) -> Self
Saturating multiplication.
Multiplies a positive integer by another positive integer, returning a positive result.
Returns PositiveIsize::MAX on overflow.
Sourcepub const fn saturating_pow(self, rhs: u32) -> Self
pub const fn saturating_pow(self, rhs: u32) -> Self
Saturating integer exponentiation.
Raises positive value to an integer power.
Returns PositiveIsize::MAX on overflow.
Trait Implementations§
Source§impl Binary for PositiveIsize
impl Binary for PositiveIsize
Source§impl BitAnd<NegativeIsize> for PositiveIsize
impl BitAnd<NegativeIsize> for PositiveIsize
Source§type Output = PositiveIsize
type Output = PositiveIsize
& operator.Source§impl BitAnd<PositiveIsize> for NegativeIsize
impl BitAnd<PositiveIsize> for NegativeIsize
Source§type Output = PositiveIsize
type Output = PositiveIsize
& operator.Source§impl BitAnd<PositiveIsize> for isize
impl BitAnd<PositiveIsize> for isize
Source§type Output = PositiveIsize
type Output = PositiveIsize
& operator.Source§impl BitAnd<isize> for PositiveIsize
impl BitAnd<isize> for PositiveIsize
Source§impl BitAnd for PositiveIsize
impl BitAnd for PositiveIsize
Source§impl BitAndAssign<NegativeIsize> for PositiveIsize
impl BitAndAssign<NegativeIsize> for PositiveIsize
Source§fn bitand_assign(&mut self, rhs: NegativeIsize)
fn bitand_assign(&mut self, rhs: NegativeIsize)
&= operation. Read moreSource§impl BitAndAssign<isize> for PositiveIsize
impl BitAndAssign<isize> for PositiveIsize
Source§fn bitand_assign(&mut self, rhs: isize)
fn bitand_assign(&mut self, rhs: isize)
&= operation. Read moreSource§impl BitAndAssign for PositiveIsize
impl BitAndAssign for PositiveIsize
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl BitOr<NegativeIsize> for PositiveIsize
impl BitOr<NegativeIsize> for PositiveIsize
Source§type Output = NegativeIsize
type Output = NegativeIsize
| operator.Source§impl BitOr<PositiveIsize> for NegativeIsize
impl BitOr<PositiveIsize> for NegativeIsize
Source§type Output = NegativeIsize
type Output = NegativeIsize
| operator.Source§impl BitOr for PositiveIsize
impl BitOr for PositiveIsize
Source§impl BitOrAssign<PositiveIsize> for NegativeIsize
impl BitOrAssign<PositiveIsize> for NegativeIsize
Source§fn bitor_assign(&mut self, rhs: PositiveIsize)
fn bitor_assign(&mut self, rhs: PositiveIsize)
|= operation. Read moreSource§impl BitOrAssign for PositiveIsize
impl BitOrAssign for PositiveIsize
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl BitXor<NegativeIsize> for PositiveIsize
impl BitXor<NegativeIsize> for PositiveIsize
Source§type Output = NegativeIsize
type Output = NegativeIsize
^ operator.Source§impl BitXor<PositiveIsize> for NegativeIsize
impl BitXor<PositiveIsize> for NegativeIsize
Source§type Output = NegativeIsize
type Output = NegativeIsize
^ operator.Source§impl BitXor for PositiveIsize
impl BitXor for PositiveIsize
Source§impl BitXorAssign<PositiveIsize> for NegativeIsize
impl BitXorAssign<PositiveIsize> for NegativeIsize
Source§fn bitxor_assign(&mut self, rhs: PositiveIsize)
fn bitxor_assign(&mut self, rhs: PositiveIsize)
^= operation. Read moreSource§impl BitXorAssign for PositiveIsize
impl BitXorAssign for PositiveIsize
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreSource§impl Clone for PositiveIsize
impl Clone for PositiveIsize
Source§fn clone(&self) -> PositiveIsize
fn clone(&self) -> PositiveIsize
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PositiveIsize
impl Debug for PositiveIsize
Source§impl Default for PositiveIsize
impl Default for PositiveIsize
Source§impl Display for PositiveIsize
impl Display for PositiveIsize
Source§impl Div<usize> for PositiveIsize
impl Div<usize> for PositiveIsize
Source§impl Div for PositiveIsize
impl Div for PositiveIsize
Source§impl DivAssign<usize> for PositiveIsize
impl DivAssign<usize> for PositiveIsize
Source§fn div_assign(&mut self, rhs: usize)
fn div_assign(&mut self, rhs: usize)
/= operation. Read moreSource§impl DivAssign for PositiveIsize
impl DivAssign for PositiveIsize
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl From<PositiveI16> for PositiveIsize
impl From<PositiveI16> for PositiveIsize
Source§fn from(value: PositiveI16) -> Self
fn from(value: PositiveI16) -> Self
Source§impl From<PositiveI8> for PositiveIsize
impl From<PositiveI8> for PositiveIsize
Source§fn from(value: PositiveI8) -> Self
fn from(value: PositiveI8) -> Self
Source§impl From<PositiveIsize> for isize
impl From<PositiveIsize> for isize
Source§fn from(value: PositiveIsize) -> Self
fn from(value: PositiveIsize) -> Self
Source§impl From<PositiveIsize> for usize
impl From<PositiveIsize> for usize
Source§fn from(value: PositiveIsize) -> Self
fn from(value: PositiveIsize) -> Self
Source§impl From<u8> for PositiveIsize
impl From<u8> for PositiveIsize
Source§impl FromStr for PositiveIsize
impl FromStr for PositiveIsize
Source§impl Hash for PositiveIsize
impl Hash for PositiveIsize
Source§impl LowerHex for PositiveIsize
impl LowerHex for PositiveIsize
Source§impl Not for PositiveIsize
impl Not for PositiveIsize
Source§impl Octal for PositiveIsize
impl Octal for PositiveIsize
Source§impl Ord for PositiveIsize
impl Ord for PositiveIsize
Source§impl PartialEq for PositiveIsize
impl PartialEq for PositiveIsize
Source§impl PartialOrd for PositiveIsize
impl PartialOrd for PositiveIsize
Source§impl Rem<usize> for PositiveIsize
impl Rem<usize> for PositiveIsize
Source§impl Rem for PositiveIsize
impl Rem for PositiveIsize
Source§impl RemAssign<usize> for PositiveIsize
impl RemAssign<usize> for PositiveIsize
Source§fn rem_assign(&mut self, rhs: usize)
fn rem_assign(&mut self, rhs: usize)
%= operation. Read moreSource§impl RemAssign for PositiveIsize
impl RemAssign for PositiveIsize
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read more