PositiveI16

Struct PositiveI16 

Source
#[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

Source

pub const BITS: u32 = 16u32

The size of this positive integer type in bits.

This value is equal to i16::BITS.

Source

pub const MIN: Self

The smallest value that can be represented by this positive integer type, 0.

Source

pub const MAX: Self

The largest value that can be represented by this positive integer type, equal to i16::MAX.

Source

pub const fn new(value: i16) -> Option<Self>

Creates a PositiveI16 if the given value is positive.

Source

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.

Source

pub const fn get(self) -> i16

Returns the contained value as a primitive type.

Source

pub const fn count_zeros(self) -> u32

Returns the number of zeros in the binary representation of self.

Source

pub const fn count_ones(self) -> u32

Returns the number of ones in the binary representation of self.

Source

pub const fn leading_zeros(self) -> u32

Returns the number of leading zeros in the binary representation of self.

Source

pub const fn trailing_zeros(self) -> u32

Returns the number of trailing zeros in the binary representation of self.

Source

pub const fn is_power_of_two(self) -> bool

Returns true if and only if self == (1 << k) for some k.

Source

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.

Source

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.

Source

pub const fn checked_neg(self) -> Option<NegativeI16>

Checked negation. Computes -self, returning None if self == 0.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn saturating_add(self, rhs: Self) -> Self

Saturating addition. Adds a positive integer to another positive integer. Returns PositiveI16::MAX on overflow.

Source

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.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl BitAnd<NegativeI16> for PositiveI16

Source§

type Output = PositiveI16

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: NegativeI16) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd<PositiveI16> for NegativeI16

Source§

type Output = PositiveI16

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: PositiveI16) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd<PositiveI16> for i16

Source§

type Output = PositiveI16

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: PositiveI16) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd<i16> for PositiveI16

Source§

type Output = PositiveI16

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: i16) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd for PositiveI16

Source§

type Output = PositiveI16

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAndAssign<NegativeI16> for PositiveI16

Source§

fn bitand_assign(&mut self, rhs: NegativeI16)

Performs the &= operation. Read more
Source§

impl BitAndAssign<i16> for PositiveI16

Source§

fn bitand_assign(&mut self, rhs: i16)

Performs the &= operation. Read more
Source§

impl BitAndAssign for PositiveI16

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr<NegativeI16> for PositiveI16

Source§

type Output = NegativeI16

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: NegativeI16) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr<PositiveI16> for NegativeI16

Source§

type Output = NegativeI16

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: PositiveI16) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr for PositiveI16

Source§

type Output = PositiveI16

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOrAssign<PositiveI16> for NegativeI16

Source§

fn bitor_assign(&mut self, rhs: PositiveI16)

Performs the |= operation. Read more
Source§

impl BitOrAssign for PositiveI16

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl BitXor<NegativeI16> for PositiveI16

Source§

type Output = NegativeI16

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: NegativeI16) -> Self::Output

Performs the ^ operation. Read more
Source§

impl BitXor<PositiveI16> for NegativeI16

Source§

type Output = NegativeI16

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: PositiveI16) -> Self::Output

Performs the ^ operation. Read more
Source§

impl BitXor for PositiveI16

Source§

type Output = PositiveI16

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl BitXorAssign<PositiveI16> for NegativeI16

Source§

fn bitxor_assign(&mut self, rhs: PositiveI16)

Performs the ^= operation. Read more
Source§

impl BitXorAssign for PositiveI16

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl Clone for PositiveI16

Source§

fn clone(&self) -> PositiveI16

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PositiveI16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PositiveI16

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for PositiveI16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<u16> for PositiveI16

Source§

type Output = PositiveI16

The resulting type after applying the / operator.
Source§

fn div(self, rhs: u16) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for PositiveI16

Source§

type Output = PositiveI16

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign<u16> for PositiveI16

Source§

fn div_assign(&mut self, rhs: u16)

Performs the /= operation. Read more
Source§

impl DivAssign for PositiveI16

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl From<PositiveI16> for PositiveI32

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for PositiveI64

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for PositiveIsize

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for i128

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for i16

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for i32

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for i64

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for isize

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for u128

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for u16

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for u32

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for u64

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI16> for usize

Source§

fn from(value: PositiveI16) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveI8> for PositiveI16

Source§

fn from(value: PositiveI8) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for PositiveI16

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl FromStr for PositiveI16

Source§

type Err = IntErrorKind

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for PositiveI16

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl LowerHex for PositiveI16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Not for PositiveI16

Source§

type Output = NegativeI16

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl Octal for PositiveI16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for PositiveI16

Source§

fn cmp(&self, rhs: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for PositiveI16

Source§

fn eq(&self, rhs: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for PositiveI16

Source§

fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Rem<u16> for PositiveI16

Source§

type Output = PositiveI16

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: u16) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem for PositiveI16

Source§

type Output = PositiveI16

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
Source§

impl RemAssign<u16> for PositiveI16

Source§

fn rem_assign(&mut self, rhs: u16)

Performs the %= operation. Read more
Source§

impl RemAssign for PositiveI16

Source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
Source§

impl TryFrom<PositiveI16> for PositiveI8

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: PositiveI16) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<PositiveI16> for i8

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: PositiveI16) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<PositiveI16> for u8

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: PositiveI16) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<PositiveI32> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: PositiveI32) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<PositiveI64> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: PositiveI64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<PositiveIsize> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: PositiveIsize) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i128> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: i128) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i16> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: i16) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i32> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: i32) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i64> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: i64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i8> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: i8) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<isize> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: isize) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u128> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: u128) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u16> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: u16) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u32> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: u32) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u64> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: u64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<usize> for PositiveI16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: usize) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl UpperHex for PositiveI16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for PositiveI16

Source§

impl Eq for PositiveI16

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.