NegativeI32

Struct NegativeI32 

Source
#[repr(C, align(4))]
pub struct NegativeI32 { /* private fields */ }
Expand description

A signed value that is known to be negative.

This enables some memory layout optimization. For example, Option<NegativeI32> is the same size as i32.

Implementations§

Source§

impl NegativeI32

Source

pub const BITS: u32 = 32u32

The size of this negative integer type in bits.

This value is equal to i32::BITS.

Source

pub const MIN: Self

The smallest value that can be represented by this negative integer type, equal to i32::MIN.

Source

pub const MAX: Self

The largest value that can be represented by this negative integer type, -1.

Source

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

Creates a NegativeI32 if the given value is negative.

Source

pub const unsafe fn new_unchecked(value: i32) -> Self

Creates a NegativeI32 without checking whether the value is negative. This results in undefined behaviour if the value is positive.

§Safety

The value must not be positive.

Source

pub const fn get(self) -> i32

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.

Since the value is guaranteed to be negative, this function always returns 0.

Source

pub const fn trailing_zeros(self) -> u32

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

On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.

Source

pub const fn checked_abs(self) -> Option<PositiveI32>

Checked absolute value. Computes -self, returning None if self == MIN.

Source

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

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

Source

pub const fn checked_add(self, rhs: Self) -> Option<Self>

Checked addition. Adds a negative integer to another negative integer. Checks for overflow and returns None on overflow. As a consequence, the result cannot wrap to positive integers.

Source

pub const fn checked_sub(self, rhs: Self) -> Option<Self>

Checked subtraction. Subtracts a negative integer from another negative integer. Returns None if the result would overflow into a positive integer.

Source

pub const fn checked_mul(self, rhs: Self) -> Option<PositiveI32>

Checked multiplication. Multiplies a negative integer by another negative integer, returning a positive result. Returns None if the result would overflow.

Source

pub const fn checked_mul_positive(self, rhs: PositiveI32) -> Option<Self>

Checked sign-preserving multiplication. Multiplies a negative integer by a positive integer, returning a negative result. Returns None if rhs == 0 or the result would overflow.

Source

pub const fn checked_div(self, rhs: Self) -> Option<PositiveI32>

Checked division. Divides a negative integer by another negative integer, returning the positive quotient. Returns None if the result would overflow.

The only case where such an overflow can occur is when one divides MIN / -1; this is equivalent to -MIN, a positive value that is too large to represent as a PositiveI32.

Source

pub const fn checked_div_euclid(self, rhs: Self) -> Option<PositiveI32>

Checked Euclidean division. Calculates the Euclidean quotient of two negative integers, returning the positive result. Returns None if the result would overflow.

The only case where such an overflow can occur is when one divides MIN / -1; this is equivalent to -MIN, a positive value that is too large to represent as a PositiveI32.

Source

pub const fn checked_rem_euclid(self, rhs: i32) -> Option<PositiveI32>

Checked Euclidean remainder. Calculates the Euclidean remainder of a negative integer and any signed integer, returning the positive result. Returns None if rhs == 0 or the result would overflow.

The only case where such an overflow can occur is when one divides MIN / -1; this is equivalent to -MIN, a positive value that is too large to represent as a PositiveI32.

Source

pub const fn saturating_abs(self) -> PositiveI32

Saturating absolute value. Computes -self, returning PositiveI32::MAX if self == MIN.

Source

pub const fn saturating_neg(self) -> PositiveI32

Saturating negation. Computes -self, returning PositiveI32::MAX if self == MIN.

Source

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

Saturating addition. Adds a negative integer to another negative integer. Returns NegativeI32::MIN on overflow.

Source

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

Saturating subtraction. Subtracts a negative integer from another negative integer. Returns -1 if the result would overflow into a positive integer.

Source

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

Saturating multiplication. Multiplies a negative integer by another negative integer, returning a positive result. Returns PositiveI32::MAX on overflow.

Source

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

Saturating sign-preserving multiplication. Multiplies a negative integer by a positive integer, returning a negative result. Returns -1 if rhs == 0. Returns NegativeI32::MIN on overflow.

Trait Implementations§

Source§

impl Binary for NegativeI32

Source§

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

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

impl BitAnd<NegativeI32> for PositiveI32

Source§

type Output = PositiveI32

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAnd<PositiveI32> for NegativeI32

Source§

type Output = PositiveI32

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAnd for NegativeI32

Source§

type Output = NegativeI32

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAndAssign<NegativeI32> for PositiveI32

Source§

fn bitand_assign(&mut self, rhs: NegativeI32)

Performs the &= operation. Read more
Source§

impl BitAndAssign for NegativeI32

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr<NegativeI32> for PositiveI32

Source§

type Output = NegativeI32

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOr<NegativeI32> for i32

Source§

type Output = NegativeI32

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOr<PositiveI32> for NegativeI32

Source§

type Output = NegativeI32

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOr<i32> for NegativeI32

Source§

type Output = NegativeI32

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOr for NegativeI32

Source§

type Output = NegativeI32

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOrAssign<PositiveI32> for NegativeI32

Source§

fn bitor_assign(&mut self, rhs: PositiveI32)

Performs the |= operation. Read more
Source§

impl BitOrAssign<i32> for NegativeI32

Source§

fn bitor_assign(&mut self, rhs: i32)

Performs the |= operation. Read more
Source§

impl BitOrAssign for NegativeI32

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl BitXor<NegativeI32> for PositiveI32

Source§

type Output = NegativeI32

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl BitXor<PositiveI32> for NegativeI32

Source§

type Output = NegativeI32

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl BitXor for NegativeI32

Source§

type Output = PositiveI32

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl BitXorAssign<PositiveI32> for NegativeI32

Source§

fn bitxor_assign(&mut self, rhs: PositiveI32)

Performs the ^= operation. Read more
Source§

impl Clone for NegativeI32

Source§

fn clone(&self) -> NegativeI32

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 NegativeI32

Source§

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

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

impl Display for NegativeI32

Source§

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

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

impl From<NegativeI16> for NegativeI32

Source§

fn from(value: NegativeI16) -> Self

Converts to this type from the input type.
Source§

impl From<NegativeI32> for NegativeI64

Source§

fn from(value: NegativeI32) -> Self

Converts to this type from the input type.
Source§

impl From<NegativeI32> for i128

Source§

fn from(value: NegativeI32) -> Self

Converts to this type from the input type.
Source§

impl From<NegativeI32> for i32

Source§

fn from(value: NegativeI32) -> Self

Converts to this type from the input type.
Source§

impl From<NegativeI32> for i64

Source§

fn from(value: NegativeI32) -> Self

Converts to this type from the input type.
Source§

impl From<NegativeI8> for NegativeI32

Source§

fn from(value: NegativeI8) -> Self

Converts to this type from the input type.
Source§

impl FromStr for NegativeI32

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 NegativeI32

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 NegativeI32

Source§

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

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

impl Not for NegativeI32

Source§

type Output = PositiveI32

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl Octal for NegativeI32

Source§

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

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

impl Ord for NegativeI32

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 NegativeI32

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 NegativeI32

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 TryFrom<NegativeI32> for NegativeI16

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeI32> for NegativeI8

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeI32> for NegativeIsize

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeI32> for i16

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeI32> for i8

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeI32> for isize

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeI64> for NegativeI32

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<i128> for NegativeI32

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 NegativeI32

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 NegativeI32

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 NegativeI32

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 NegativeI32

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 NegativeI32

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 UpperHex for NegativeI32

Source§

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

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

impl Copy for NegativeI32

Source§

impl Eq for NegativeI32

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.