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