Skip to main content

NonZeroPrimitiveSigned

Trait NonZeroPrimitiveSigned 

Source
pub trait NonZeroPrimitiveSigned:
    NonZeroPrimitiveInteger<Integer: PrimitiveSigned>
    + From<NonZero<i8>>
    + Neg<Output = Self> {
    type NonZeroUnsigned: NonZeroPrimitiveUnsigned;

Show 13 methods // Required methods fn abs(self) -> Self; fn cast_unsigned(self) -> Self::NonZeroUnsigned; fn checked_abs(self) -> Option<Self>; fn checked_neg(self) -> Option<Self>; fn is_positive(self) -> bool; fn is_negative(self) -> bool; fn overflowing_abs(self) -> (Self, bool); fn overflowing_neg(self) -> (Self, bool); fn saturating_abs(self) -> Self; fn saturating_neg(self) -> Self; fn unsigned_abs(self) -> Self::NonZeroUnsigned; fn wrapping_abs(self) -> Self; fn wrapping_neg(self) -> Self;
}
Expand description

Trait for NonZero primitive signed integers, including the supertrait NonZeroPrimitiveInteger.

This encapsulates trait implementations and inherent methods that are common among all of the implementations of NonZero<T>, where T is a PrimitiveSigned.

See the corresponding items on the individual types for more documentation and examples.

This trait is sealed with a private trait to prevent downstream implementations, so we may continue to expand along with the standard library without worrying about breaking changes for implementors.

§Examples

use num_primitive::NonZeroPrimitiveSigned;
use core::num::NonZero;

fn sign_and_magnitude<T: NonZeroPrimitiveSigned>(n: T) -> (bool, T::NonZeroUnsigned) {
    (n.is_negative(), n.unsigned_abs())
}

let n = NonZero::new(-42i16).unwrap();
assert_eq!(sign_and_magnitude(n), (true, NonZero::new(42u16).unwrap()));

Required Associated Types§

Source

type NonZeroUnsigned: NonZeroPrimitiveUnsigned

The unsigned non-zero integer type used by methods like cast_unsigned.

For core::num::NonZero<T>, this is NonZero<T::Unsigned>.

Required Methods§

Source

fn abs(self) -> Self

Computes the absolute value of self.

Source

fn cast_unsigned(self) -> Self::NonZeroUnsigned

Returns the bit pattern of self reinterpreted as an unsigned integer of the same size.

Source

fn checked_abs(self) -> Option<Self>

Checked absolute value. Checks for overflow and returns None if self == Self::MIN.

Source

fn checked_neg(self) -> Option<Self>

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

Source

fn is_positive(self) -> bool

Returns true if self is positive and false if the number is negative.

Source

fn is_negative(self) -> bool

Returns true if self is negative and false if the number is positive.

Source

fn overflowing_abs(self) -> (Self, bool)

Computes the absolute value of self, with overflow information.

Source

fn overflowing_neg(self) -> (Self, bool)

Negates self, overflowing if this is equal to the minimum value.

Source

fn saturating_abs(self) -> Self

Saturating absolute value.

Source

fn saturating_neg(self) -> Self

Saturating negation. Computes -self, returning Self::MAX if self == Self::MIN instead of overflowing.

Source

fn unsigned_abs(self) -> Self::NonZeroUnsigned

Computes the absolute value of self without any wrapping or panicking.

Source

fn wrapping_abs(self) -> Self

Wrapping absolute value.

Source

fn wrapping_neg(self) -> Self

Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl NonZeroPrimitiveSigned for NonZero<i8>

Source§

fn abs(self) -> Self

See the inherent abs method.

Source§

fn cast_unsigned(self) -> Self::NonZeroUnsigned

See the inherent cast_unsigned method.

Source§

fn checked_abs(self) -> Option<Self>

See the inherent checked_abs method.

Source§

fn checked_neg(self) -> Option<Self>

See the inherent checked_neg method.

Source§

fn is_negative(self) -> bool

See the inherent is_negative method.

Source§

fn is_positive(self) -> bool

See the inherent is_positive method.

Source§

fn overflowing_abs(self) -> (Self, bool)

See the inherent overflowing_abs method.

Source§

fn overflowing_neg(self) -> (Self, bool)

See the inherent overflowing_neg method.

Source§

fn saturating_abs(self) -> Self

See the inherent saturating_abs method.

Source§

fn saturating_neg(self) -> Self

See the inherent saturating_neg method.

Source§

fn unsigned_abs(self) -> Self::NonZeroUnsigned

See the inherent unsigned_abs method.

Source§

fn wrapping_abs(self) -> Self

See the inherent wrapping_abs method.

Source§

fn wrapping_neg(self) -> Self

See the inherent wrapping_neg method.

Source§

type NonZeroUnsigned = NonZero<u8>

Source§

impl NonZeroPrimitiveSigned for NonZero<i16>

Source§

fn abs(self) -> Self

See the inherent abs method.

Source§

fn cast_unsigned(self) -> Self::NonZeroUnsigned

See the inherent cast_unsigned method.

Source§

fn checked_abs(self) -> Option<Self>

See the inherent checked_abs method.

Source§

fn checked_neg(self) -> Option<Self>

See the inherent checked_neg method.

Source§

fn is_negative(self) -> bool

See the inherent is_negative method.

Source§

fn is_positive(self) -> bool

See the inherent is_positive method.

Source§

fn overflowing_abs(self) -> (Self, bool)

See the inherent overflowing_abs method.

Source§

fn overflowing_neg(self) -> (Self, bool)

See the inherent overflowing_neg method.

Source§

fn saturating_abs(self) -> Self

See the inherent saturating_abs method.

Source§

fn saturating_neg(self) -> Self

See the inherent saturating_neg method.

Source§

fn unsigned_abs(self) -> Self::NonZeroUnsigned

See the inherent unsigned_abs method.

Source§

fn wrapping_abs(self) -> Self

See the inherent wrapping_abs method.

Source§

fn wrapping_neg(self) -> Self

See the inherent wrapping_neg method.

Source§

type NonZeroUnsigned = NonZero<u16>

Source§

impl NonZeroPrimitiveSigned for NonZero<i32>

Source§

fn abs(self) -> Self

See the inherent abs method.

Source§

fn cast_unsigned(self) -> Self::NonZeroUnsigned

See the inherent cast_unsigned method.

Source§

fn checked_abs(self) -> Option<Self>

See the inherent checked_abs method.

Source§

fn checked_neg(self) -> Option<Self>

See the inherent checked_neg method.

Source§

fn is_negative(self) -> bool

See the inherent is_negative method.

Source§

fn is_positive(self) -> bool

See the inherent is_positive method.

Source§

fn overflowing_abs(self) -> (Self, bool)

See the inherent overflowing_abs method.

Source§

fn overflowing_neg(self) -> (Self, bool)

See the inherent overflowing_neg method.

Source§

fn saturating_abs(self) -> Self

See the inherent saturating_abs method.

Source§

fn saturating_neg(self) -> Self

See the inherent saturating_neg method.

Source§

fn unsigned_abs(self) -> Self::NonZeroUnsigned

See the inherent unsigned_abs method.

Source§

fn wrapping_abs(self) -> Self

See the inherent wrapping_abs method.

Source§

fn wrapping_neg(self) -> Self

See the inherent wrapping_neg method.

Source§

type NonZeroUnsigned = NonZero<u32>

Source§

impl NonZeroPrimitiveSigned for NonZero<i64>

Source§

fn abs(self) -> Self

See the inherent abs method.

Source§

fn cast_unsigned(self) -> Self::NonZeroUnsigned

See the inherent cast_unsigned method.

Source§

fn checked_abs(self) -> Option<Self>

See the inherent checked_abs method.

Source§

fn checked_neg(self) -> Option<Self>

See the inherent checked_neg method.

Source§

fn is_negative(self) -> bool

See the inherent is_negative method.

Source§

fn is_positive(self) -> bool

See the inherent is_positive method.

Source§

fn overflowing_abs(self) -> (Self, bool)

See the inherent overflowing_abs method.

Source§

fn overflowing_neg(self) -> (Self, bool)

See the inherent overflowing_neg method.

Source§

fn saturating_abs(self) -> Self

See the inherent saturating_abs method.

Source§

fn saturating_neg(self) -> Self

See the inherent saturating_neg method.

Source§

fn unsigned_abs(self) -> Self::NonZeroUnsigned

See the inherent unsigned_abs method.

Source§

fn wrapping_abs(self) -> Self

See the inherent wrapping_abs method.

Source§

fn wrapping_neg(self) -> Self

See the inherent wrapping_neg method.

Source§

type NonZeroUnsigned = NonZero<u64>

Source§

impl NonZeroPrimitiveSigned for NonZero<i128>

Source§

fn abs(self) -> Self

See the inherent abs method.

Source§

fn cast_unsigned(self) -> Self::NonZeroUnsigned

See the inherent cast_unsigned method.

Source§

fn checked_abs(self) -> Option<Self>

See the inherent checked_abs method.

Source§

fn checked_neg(self) -> Option<Self>

See the inherent checked_neg method.

Source§

fn is_negative(self) -> bool

See the inherent is_negative method.

Source§

fn is_positive(self) -> bool

See the inherent is_positive method.

Source§

fn overflowing_abs(self) -> (Self, bool)

See the inherent overflowing_abs method.

Source§

fn overflowing_neg(self) -> (Self, bool)

See the inherent overflowing_neg method.

Source§

fn saturating_abs(self) -> Self

See the inherent saturating_abs method.

Source§

fn saturating_neg(self) -> Self

See the inherent saturating_neg method.

Source§

fn unsigned_abs(self) -> Self::NonZeroUnsigned

See the inherent unsigned_abs method.

Source§

fn wrapping_abs(self) -> Self

See the inherent wrapping_abs method.

Source§

fn wrapping_neg(self) -> Self

See the inherent wrapping_neg method.

Source§

type NonZeroUnsigned = NonZero<u128>

Source§

impl NonZeroPrimitiveSigned for NonZero<isize>

Source§

fn abs(self) -> Self

See the inherent abs method.

Source§

fn cast_unsigned(self) -> Self::NonZeroUnsigned

See the inherent cast_unsigned method.

Source§

fn checked_abs(self) -> Option<Self>

See the inherent checked_abs method.

Source§

fn checked_neg(self) -> Option<Self>

See the inherent checked_neg method.

Source§

fn is_negative(self) -> bool

See the inherent is_negative method.

Source§

fn is_positive(self) -> bool

See the inherent is_positive method.

Source§

fn overflowing_abs(self) -> (Self, bool)

See the inherent overflowing_abs method.

Source§

fn overflowing_neg(self) -> (Self, bool)

See the inherent overflowing_neg method.

Source§

fn saturating_abs(self) -> Self

See the inherent saturating_abs method.

Source§

fn saturating_neg(self) -> Self

See the inherent saturating_neg method.

Source§

fn unsigned_abs(self) -> Self::NonZeroUnsigned

See the inherent unsigned_abs method.

Source§

fn wrapping_abs(self) -> Self

See the inherent wrapping_abs method.

Source§

fn wrapping_neg(self) -> Self

See the inherent wrapping_neg method.

Source§

type NonZeroUnsigned = NonZero<usize>

Implementors§