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§
Sourcetype NonZeroUnsigned: NonZeroPrimitiveUnsigned
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§
Sourcefn cast_unsigned(self) -> Self::NonZeroUnsigned
fn cast_unsigned(self) -> Self::NonZeroUnsigned
Returns the bit pattern of self reinterpreted as an unsigned integer of the same size.
Sourcefn checked_abs(self) -> Option<Self>
fn checked_abs(self) -> Option<Self>
Checked absolute value. Checks for overflow and returns None if self == Self::MIN.
Sourcefn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
Checked negation. Computes -self, returning None if self == Self::MIN.
Sourcefn is_positive(self) -> bool
fn is_positive(self) -> bool
Returns true if self is positive and false if the number is negative.
Sourcefn is_negative(self) -> bool
fn is_negative(self) -> bool
Returns true if self is negative and false if the number is positive.
Sourcefn overflowing_abs(self) -> (Self, bool)
fn overflowing_abs(self) -> (Self, bool)
Computes the absolute value of self, with overflow information.
Sourcefn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
Negates self, overflowing if this is equal to the minimum value.
Sourcefn saturating_abs(self) -> Self
fn saturating_abs(self) -> Self
Saturating absolute value.
Sourcefn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
Saturating negation. Computes -self, returning Self::MAX
if self == Self::MIN instead of overflowing.
Sourcefn unsigned_abs(self) -> Self::NonZeroUnsigned
fn unsigned_abs(self) -> Self::NonZeroUnsigned
Computes the absolute value of self without any wrapping or panicking.
Sourcefn wrapping_abs(self) -> Self
fn wrapping_abs(self) -> Self
Wrapping absolute value.
Sourcefn wrapping_neg(self) -> Self
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>
impl NonZeroPrimitiveSigned for NonZero<i8>
Source§fn cast_unsigned(self) -> Self::NonZeroUnsigned
fn cast_unsigned(self) -> Self::NonZeroUnsigned
See the inherent cast_unsigned method.
Source§fn checked_abs(self) -> Option<Self>
fn checked_abs(self) -> Option<Self>
See the inherent checked_abs method.
Source§fn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
See the inherent checked_neg method.
Source§fn is_negative(self) -> bool
fn is_negative(self) -> bool
See the inherent is_negative method.
Source§fn is_positive(self) -> bool
fn is_positive(self) -> bool
See the inherent is_positive method.
Source§fn overflowing_abs(self) -> (Self, bool)
fn overflowing_abs(self) -> (Self, bool)
See the inherent overflowing_abs method.
Source§fn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
See the inherent overflowing_neg method.
Source§fn saturating_abs(self) -> Self
fn saturating_abs(self) -> Self
See the inherent saturating_abs method.
Source§fn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
See the inherent saturating_neg method.
Source§fn unsigned_abs(self) -> Self::NonZeroUnsigned
fn unsigned_abs(self) -> Self::NonZeroUnsigned
See the inherent unsigned_abs method.
Source§fn wrapping_abs(self) -> Self
fn wrapping_abs(self) -> Self
See the inherent wrapping_abs method.
Source§fn wrapping_neg(self) -> Self
fn wrapping_neg(self) -> Self
See the inherent wrapping_neg method.
type NonZeroUnsigned = NonZero<u8>
Source§impl NonZeroPrimitiveSigned for NonZero<i16>
impl NonZeroPrimitiveSigned for NonZero<i16>
Source§fn cast_unsigned(self) -> Self::NonZeroUnsigned
fn cast_unsigned(self) -> Self::NonZeroUnsigned
See the inherent cast_unsigned method.
Source§fn checked_abs(self) -> Option<Self>
fn checked_abs(self) -> Option<Self>
See the inherent checked_abs method.
Source§fn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
See the inherent checked_neg method.
Source§fn is_negative(self) -> bool
fn is_negative(self) -> bool
See the inherent is_negative method.
Source§fn is_positive(self) -> bool
fn is_positive(self) -> bool
See the inherent is_positive method.
Source§fn overflowing_abs(self) -> (Self, bool)
fn overflowing_abs(self) -> (Self, bool)
See the inherent overflowing_abs method.
Source§fn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
See the inherent overflowing_neg method.
Source§fn saturating_abs(self) -> Self
fn saturating_abs(self) -> Self
See the inherent saturating_abs method.
Source§fn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
See the inherent saturating_neg method.
Source§fn unsigned_abs(self) -> Self::NonZeroUnsigned
fn unsigned_abs(self) -> Self::NonZeroUnsigned
See the inherent unsigned_abs method.
Source§fn wrapping_abs(self) -> Self
fn wrapping_abs(self) -> Self
See the inherent wrapping_abs method.
Source§fn wrapping_neg(self) -> Self
fn wrapping_neg(self) -> Self
See the inherent wrapping_neg method.
type NonZeroUnsigned = NonZero<u16>
Source§impl NonZeroPrimitiveSigned for NonZero<i32>
impl NonZeroPrimitiveSigned for NonZero<i32>
Source§fn cast_unsigned(self) -> Self::NonZeroUnsigned
fn cast_unsigned(self) -> Self::NonZeroUnsigned
See the inherent cast_unsigned method.
Source§fn checked_abs(self) -> Option<Self>
fn checked_abs(self) -> Option<Self>
See the inherent checked_abs method.
Source§fn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
See the inherent checked_neg method.
Source§fn is_negative(self) -> bool
fn is_negative(self) -> bool
See the inherent is_negative method.
Source§fn is_positive(self) -> bool
fn is_positive(self) -> bool
See the inherent is_positive method.
Source§fn overflowing_abs(self) -> (Self, bool)
fn overflowing_abs(self) -> (Self, bool)
See the inherent overflowing_abs method.
Source§fn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
See the inherent overflowing_neg method.
Source§fn saturating_abs(self) -> Self
fn saturating_abs(self) -> Self
See the inherent saturating_abs method.
Source§fn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
See the inherent saturating_neg method.
Source§fn unsigned_abs(self) -> Self::NonZeroUnsigned
fn unsigned_abs(self) -> Self::NonZeroUnsigned
See the inherent unsigned_abs method.
Source§fn wrapping_abs(self) -> Self
fn wrapping_abs(self) -> Self
See the inherent wrapping_abs method.
Source§fn wrapping_neg(self) -> Self
fn wrapping_neg(self) -> Self
See the inherent wrapping_neg method.
type NonZeroUnsigned = NonZero<u32>
Source§impl NonZeroPrimitiveSigned for NonZero<i64>
impl NonZeroPrimitiveSigned for NonZero<i64>
Source§fn cast_unsigned(self) -> Self::NonZeroUnsigned
fn cast_unsigned(self) -> Self::NonZeroUnsigned
See the inherent cast_unsigned method.
Source§fn checked_abs(self) -> Option<Self>
fn checked_abs(self) -> Option<Self>
See the inherent checked_abs method.
Source§fn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
See the inherent checked_neg method.
Source§fn is_negative(self) -> bool
fn is_negative(self) -> bool
See the inherent is_negative method.
Source§fn is_positive(self) -> bool
fn is_positive(self) -> bool
See the inherent is_positive method.
Source§fn overflowing_abs(self) -> (Self, bool)
fn overflowing_abs(self) -> (Self, bool)
See the inherent overflowing_abs method.
Source§fn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
See the inherent overflowing_neg method.
Source§fn saturating_abs(self) -> Self
fn saturating_abs(self) -> Self
See the inherent saturating_abs method.
Source§fn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
See the inherent saturating_neg method.
Source§fn unsigned_abs(self) -> Self::NonZeroUnsigned
fn unsigned_abs(self) -> Self::NonZeroUnsigned
See the inherent unsigned_abs method.
Source§fn wrapping_abs(self) -> Self
fn wrapping_abs(self) -> Self
See the inherent wrapping_abs method.
Source§fn wrapping_neg(self) -> Self
fn wrapping_neg(self) -> Self
See the inherent wrapping_neg method.
type NonZeroUnsigned = NonZero<u64>
Source§impl NonZeroPrimitiveSigned for NonZero<i128>
impl NonZeroPrimitiveSigned for NonZero<i128>
Source§fn cast_unsigned(self) -> Self::NonZeroUnsigned
fn cast_unsigned(self) -> Self::NonZeroUnsigned
See the inherent cast_unsigned method.
Source§fn checked_abs(self) -> Option<Self>
fn checked_abs(self) -> Option<Self>
See the inherent checked_abs method.
Source§fn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
See the inherent checked_neg method.
Source§fn is_negative(self) -> bool
fn is_negative(self) -> bool
See the inherent is_negative method.
Source§fn is_positive(self) -> bool
fn is_positive(self) -> bool
See the inherent is_positive method.
Source§fn overflowing_abs(self) -> (Self, bool)
fn overflowing_abs(self) -> (Self, bool)
See the inherent overflowing_abs method.
Source§fn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
See the inherent overflowing_neg method.
Source§fn saturating_abs(self) -> Self
fn saturating_abs(self) -> Self
See the inherent saturating_abs method.
Source§fn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
See the inherent saturating_neg method.
Source§fn unsigned_abs(self) -> Self::NonZeroUnsigned
fn unsigned_abs(self) -> Self::NonZeroUnsigned
See the inherent unsigned_abs method.
Source§fn wrapping_abs(self) -> Self
fn wrapping_abs(self) -> Self
See the inherent wrapping_abs method.
Source§fn wrapping_neg(self) -> Self
fn wrapping_neg(self) -> Self
See the inherent wrapping_neg method.
type NonZeroUnsigned = NonZero<u128>
Source§impl NonZeroPrimitiveSigned for NonZero<isize>
impl NonZeroPrimitiveSigned for NonZero<isize>
Source§fn cast_unsigned(self) -> Self::NonZeroUnsigned
fn cast_unsigned(self) -> Self::NonZeroUnsigned
See the inherent cast_unsigned method.
Source§fn checked_abs(self) -> Option<Self>
fn checked_abs(self) -> Option<Self>
See the inherent checked_abs method.
Source§fn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
See the inherent checked_neg method.
Source§fn is_negative(self) -> bool
fn is_negative(self) -> bool
See the inherent is_negative method.
Source§fn is_positive(self) -> bool
fn is_positive(self) -> bool
See the inherent is_positive method.
Source§fn overflowing_abs(self) -> (Self, bool)
fn overflowing_abs(self) -> (Self, bool)
See the inherent overflowing_abs method.
Source§fn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
See the inherent overflowing_neg method.
Source§fn saturating_abs(self) -> Self
fn saturating_abs(self) -> Self
See the inherent saturating_abs method.
Source§fn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
See the inherent saturating_neg method.
Source§fn unsigned_abs(self) -> Self::NonZeroUnsigned
fn unsigned_abs(self) -> Self::NonZeroUnsigned
See the inherent unsigned_abs method.
Source§fn wrapping_abs(self) -> Self
fn wrapping_abs(self) -> Self
See the inherent wrapping_abs method.
Source§fn wrapping_neg(self) -> Self
fn wrapping_neg(self) -> Self
See the inherent wrapping_neg method.