NegativeIsize

Struct NegativeIsize 

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

A signed value that is known to be negative.

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

Implementations§

Source§

impl NegativeIsize

Source

pub const BITS: u32 = 64u32

The size of this negative integer type in bits.

This value is equal to isize::BITS.

Source

pub const MIN: Self

The smallest value that can be represented by this negative integer type, equal to isize::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: isize) -> Option<Self>

Creates a NegativeIsize if the given value is negative.

Source

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

Creates a NegativeIsize 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) -> isize

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<PositiveIsize>

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

Source

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

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<PositiveIsize>

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: PositiveIsize) -> 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<PositiveIsize>

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 PositiveIsize.

Source

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

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 PositiveIsize.

Source

pub const fn checked_rem_euclid(self, rhs: isize) -> Option<PositiveIsize>

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 PositiveIsize.

Source

pub const fn saturating_abs(self) -> PositiveIsize

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

Source

pub const fn saturating_neg(self) -> PositiveIsize

Saturating negation. Computes -self, returning PositiveIsize::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 NegativeIsize::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) -> PositiveIsize

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

Source

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

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

Trait Implementations§

Source§

impl Binary for NegativeIsize

Source§

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

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

impl BitAnd<NegativeIsize> for PositiveIsize

Source§

type Output = PositiveIsize

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAnd<PositiveIsize> for NegativeIsize

Source§

type Output = PositiveIsize

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAnd for NegativeIsize

Source§

type Output = NegativeIsize

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAndAssign<NegativeIsize> for PositiveIsize

Source§

fn bitand_assign(&mut self, rhs: NegativeIsize)

Performs the &= operation. Read more
Source§

impl BitAndAssign for NegativeIsize

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr<NegativeIsize> for PositiveIsize

Source§

type Output = NegativeIsize

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOr<NegativeIsize> for isize

Source§

type Output = NegativeIsize

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOr<PositiveIsize> for NegativeIsize

Source§

type Output = NegativeIsize

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOr<isize> for NegativeIsize

Source§

type Output = NegativeIsize

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOr for NegativeIsize

Source§

type Output = NegativeIsize

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOrAssign<PositiveIsize> for NegativeIsize

Source§

fn bitor_assign(&mut self, rhs: PositiveIsize)

Performs the |= operation. Read more
Source§

impl BitOrAssign<isize> for NegativeIsize

Source§

fn bitor_assign(&mut self, rhs: isize)

Performs the |= operation. Read more
Source§

impl BitOrAssign for NegativeIsize

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl BitXor<NegativeIsize> for PositiveIsize

Source§

type Output = NegativeIsize

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl BitXor<PositiveIsize> for NegativeIsize

Source§

type Output = NegativeIsize

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl BitXor for NegativeIsize

Source§

type Output = PositiveIsize

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl BitXorAssign<PositiveIsize> for NegativeIsize

Source§

fn bitxor_assign(&mut self, rhs: PositiveIsize)

Performs the ^= operation. Read more
Source§

impl Clone for NegativeIsize

Source§

fn clone(&self) -> NegativeIsize

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 NegativeIsize

Source§

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

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

impl Display for NegativeIsize

Source§

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

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

impl From<NegativeI16> for NegativeIsize

Source§

fn from(value: NegativeI16) -> Self

Converts to this type from the input type.
Source§

impl From<NegativeI8> for NegativeIsize

Source§

fn from(value: NegativeI8) -> Self

Converts to this type from the input type.
Source§

impl From<NegativeIsize> for isize

Source§

fn from(value: NegativeIsize) -> Self

Converts to this type from the input type.
Source§

impl FromStr for NegativeIsize

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 NegativeIsize

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 NegativeIsize

Source§

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

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

impl Not for NegativeIsize

Source§

type Output = PositiveIsize

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl Octal for NegativeIsize

Source§

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

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

impl Ord for NegativeIsize

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 NegativeIsize

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 NegativeIsize

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 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<NegativeI64> for NegativeIsize

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<NegativeIsize> for NegativeI16

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeIsize> for NegativeI8

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeIsize> for i128

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeIsize> for i16

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeIsize> for i32

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeIsize> for i64

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<NegativeIsize> for i8

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl TryFrom<i128> for NegativeIsize

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 NegativeIsize

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 NegativeIsize

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 NegativeIsize

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 NegativeIsize

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 NegativeIsize

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 NegativeIsize

Source§

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

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

impl Copy for NegativeIsize

Source§

impl Eq for NegativeIsize

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.