#[repr(C, align(4))]pub struct PositiveI32 { /* private fields */ }Expand description
A signed value that is known to be positive.
This enables some memory layout optimization.
For example, Option<PositiveI32> is the same size as i32.
Implementations§
Source§impl PositiveI32
impl PositiveI32
Sourcepub const BITS: u32 = 32u32
pub const BITS: u32 = 32u32
The size of this positive integer type in bits.
This value is equal to i32::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 i32::MAX.
Sourcepub const fn new(value: i32) -> Option<Self>
pub const fn new(value: i32) -> Option<Self>
Creates a PositiveI32 if the given value is positive.
Sourcepub const unsafe fn new_unchecked(value: i32) -> Self
pub const unsafe fn new_unchecked(value: i32) -> Self
Creates a PositiveI32 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<NegativeI32>
pub const fn checked_neg(self) -> Option<NegativeI32>
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: u32) -> Option<Self>
pub const fn checked_div_unsigned(self, rhs: u32) -> 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: u32) -> Option<Self>
pub const fn checked_rem_unsigned(self, rhs: u32) -> 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 PositiveI32::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 PositiveI32::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 PositiveI32::MAX on overflow.
Trait Implementations§
Source§impl Binary for PositiveI32
impl Binary for PositiveI32
Source§impl BitAnd<NegativeI32> for PositiveI32
impl BitAnd<NegativeI32> for PositiveI32
Source§type Output = PositiveI32
type Output = PositiveI32
& operator.Source§impl BitAnd<PositiveI32> for NegativeI32
impl BitAnd<PositiveI32> for NegativeI32
Source§type Output = PositiveI32
type Output = PositiveI32
& operator.Source§impl BitAnd<PositiveI32> for i32
impl BitAnd<PositiveI32> for i32
Source§type Output = PositiveI32
type Output = PositiveI32
& operator.Source§impl BitAnd<i32> for PositiveI32
impl BitAnd<i32> for PositiveI32
Source§impl BitAnd for PositiveI32
impl BitAnd for PositiveI32
Source§impl BitAndAssign<NegativeI32> for PositiveI32
impl BitAndAssign<NegativeI32> for PositiveI32
Source§fn bitand_assign(&mut self, rhs: NegativeI32)
fn bitand_assign(&mut self, rhs: NegativeI32)
&= operation. Read moreSource§impl BitAndAssign<i32> for PositiveI32
impl BitAndAssign<i32> for PositiveI32
Source§fn bitand_assign(&mut self, rhs: i32)
fn bitand_assign(&mut self, rhs: i32)
&= operation. Read moreSource§impl BitAndAssign for PositiveI32
impl BitAndAssign for PositiveI32
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl BitOr<NegativeI32> for PositiveI32
impl BitOr<NegativeI32> for PositiveI32
Source§type Output = NegativeI32
type Output = NegativeI32
| operator.Source§impl BitOr<PositiveI32> for NegativeI32
impl BitOr<PositiveI32> for NegativeI32
Source§type Output = NegativeI32
type Output = NegativeI32
| operator.Source§impl BitOr for PositiveI32
impl BitOr for PositiveI32
Source§impl BitOrAssign<PositiveI32> for NegativeI32
impl BitOrAssign<PositiveI32> for NegativeI32
Source§fn bitor_assign(&mut self, rhs: PositiveI32)
fn bitor_assign(&mut self, rhs: PositiveI32)
|= operation. Read moreSource§impl BitOrAssign for PositiveI32
impl BitOrAssign for PositiveI32
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl BitXor<NegativeI32> for PositiveI32
impl BitXor<NegativeI32> for PositiveI32
Source§type Output = NegativeI32
type Output = NegativeI32
^ operator.Source§impl BitXor<PositiveI32> for NegativeI32
impl BitXor<PositiveI32> for NegativeI32
Source§type Output = NegativeI32
type Output = NegativeI32
^ operator.Source§impl BitXor for PositiveI32
impl BitXor for PositiveI32
Source§impl BitXorAssign<PositiveI32> for NegativeI32
impl BitXorAssign<PositiveI32> for NegativeI32
Source§fn bitxor_assign(&mut self, rhs: PositiveI32)
fn bitxor_assign(&mut self, rhs: PositiveI32)
^= operation. Read moreSource§impl BitXorAssign for PositiveI32
impl BitXorAssign for PositiveI32
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreSource§impl Clone for PositiveI32
impl Clone for PositiveI32
Source§fn clone(&self) -> PositiveI32
fn clone(&self) -> PositiveI32
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PositiveI32
impl Debug for PositiveI32
Source§impl Default for PositiveI32
impl Default for PositiveI32
Source§impl Display for PositiveI32
impl Display for PositiveI32
Source§impl Div<u32> for PositiveI32
impl Div<u32> for PositiveI32
Source§impl Div for PositiveI32
impl Div for PositiveI32
Source§impl DivAssign<u32> for PositiveI32
impl DivAssign<u32> for PositiveI32
Source§fn div_assign(&mut self, rhs: u32)
fn div_assign(&mut self, rhs: u32)
/= operation. Read moreSource§impl DivAssign for PositiveI32
impl DivAssign for PositiveI32
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl From<PositiveI16> for PositiveI32
impl From<PositiveI16> for PositiveI32
Source§fn from(value: PositiveI16) -> Self
fn from(value: PositiveI16) -> Self
Source§impl From<PositiveI32> for PositiveI64
impl From<PositiveI32> for PositiveI64
Source§fn from(value: PositiveI32) -> Self
fn from(value: PositiveI32) -> Self
Source§impl From<PositiveI32> for i128
impl From<PositiveI32> for i128
Source§fn from(value: PositiveI32) -> Self
fn from(value: PositiveI32) -> Self
Source§impl From<PositiveI32> for i32
impl From<PositiveI32> for i32
Source§fn from(value: PositiveI32) -> Self
fn from(value: PositiveI32) -> Self
Source§impl From<PositiveI32> for i64
impl From<PositiveI32> for i64
Source§fn from(value: PositiveI32) -> Self
fn from(value: PositiveI32) -> Self
Source§impl From<PositiveI32> for u128
impl From<PositiveI32> for u128
Source§fn from(value: PositiveI32) -> Self
fn from(value: PositiveI32) -> Self
Source§impl From<PositiveI32> for u32
impl From<PositiveI32> for u32
Source§fn from(value: PositiveI32) -> Self
fn from(value: PositiveI32) -> Self
Source§impl From<PositiveI32> for u64
impl From<PositiveI32> for u64
Source§fn from(value: PositiveI32) -> Self
fn from(value: PositiveI32) -> Self
Source§impl From<PositiveI8> for PositiveI32
impl From<PositiveI8> for PositiveI32
Source§fn from(value: PositiveI8) -> Self
fn from(value: PositiveI8) -> Self
Source§impl From<u16> for PositiveI32
impl From<u16> for PositiveI32
Source§impl From<u8> for PositiveI32
impl From<u8> for PositiveI32
Source§impl FromStr for PositiveI32
impl FromStr for PositiveI32
Source§impl Hash for PositiveI32
impl Hash for PositiveI32
Source§impl LowerHex for PositiveI32
impl LowerHex for PositiveI32
Source§impl Not for PositiveI32
impl Not for PositiveI32
Source§impl Octal for PositiveI32
impl Octal for PositiveI32
Source§impl Ord for PositiveI32
impl Ord for PositiveI32
Source§impl PartialEq for PositiveI32
impl PartialEq for PositiveI32
Source§impl PartialOrd for PositiveI32
impl PartialOrd for PositiveI32
Source§impl Rem<u32> for PositiveI32
impl Rem<u32> for PositiveI32
Source§impl Rem for PositiveI32
impl Rem for PositiveI32
Source§impl RemAssign<u32> for PositiveI32
impl RemAssign<u32> for PositiveI32
Source§fn rem_assign(&mut self, rhs: u32)
fn rem_assign(&mut self, rhs: u32)
%= operation. Read moreSource§impl RemAssign for PositiveI32
impl RemAssign for PositiveI32
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read more