pub trait NonZeroPrimitiveInteger:
'static
+ NonZeroSealed
+ Eq
+ Ord
+ Into<Self::Integer>
+ TryFrom<Self::Integer, Error = TryFromIntError>
+ TryFrom<NonZero<i8>, Error: PrimitiveError>
+ TryFrom<NonZero<i16>, Error: PrimitiveError>
+ TryFrom<NonZero<i32>, Error: PrimitiveError>
+ TryFrom<NonZero<i64>, Error: PrimitiveError>
+ TryFrom<NonZero<i128>, Error: PrimitiveError>
+ TryFrom<NonZero<isize>, Error: PrimitiveError>
+ TryFrom<NonZero<u8>, Error: PrimitiveError>
+ TryFrom<NonZero<u16>, Error: PrimitiveError>
+ TryFrom<NonZero<u32>, Error: PrimitiveError>
+ TryFrom<NonZero<u64>, Error: PrimitiveError>
+ TryFrom<NonZero<u128>, Error: PrimitiveError>
+ TryFrom<NonZero<usize>, Error: PrimitiveError>
+ TryInto<NonZero<i8>, Error: PrimitiveError>
+ TryInto<NonZero<i16>, Error: PrimitiveError>
+ TryInto<NonZero<i32>, Error: PrimitiveError>
+ TryInto<NonZero<i64>, Error: PrimitiveError>
+ TryInto<NonZero<i128>, Error: PrimitiveError>
+ TryInto<NonZero<isize>, Error: PrimitiveError>
+ TryInto<NonZero<u8>, Error: PrimitiveError>
+ TryInto<NonZero<u16>, Error: PrimitiveError>
+ TryInto<NonZero<u32>, Error: PrimitiveError>
+ TryInto<NonZero<u64>, Error: PrimitiveError>
+ TryInto<NonZero<u128>, Error: PrimitiveError>
+ TryInto<NonZero<usize>, Error: PrimitiveError>
+ Binary
+ Debug
+ Display
+ LowerExp
+ LowerHex
+ Octal
+ UpperExp
+ UpperHex
+ Hash
+ Copy
+ Send
+ Sync
+ Unpin
+ BitOr<Self, Output = Self>
+ BitOr<Self::Integer, Output = Self>
+ BitOrAssign<Self>
+ BitOrAssign<Self::Integer>
+ RefUnwindSafe
+ UnwindSafe
+ FromStr<Err = ParseIntError> {
type Integer: PrimitiveInteger<NonZero = Self>;
const BITS: u32;
const MAX: Self;
const MIN: Self;
// Required methods
fn checked_mul(self, other: Self) -> Option<Self>;
fn checked_pow(self, other: u32) -> Option<Self>;
fn count_ones(self) -> NonZero<u32>;
fn get(self) -> Self::Integer;
fn leading_zeros(self) -> u32;
fn new(n: Self::Integer) -> Option<Self>;
fn saturating_mul(self, other: Self) -> Self;
fn saturating_pow(self, other: u32) -> Self;
fn trailing_zeros(self) -> u32;
unsafe fn new_unchecked(n: Self::Integer) -> Self;
}Expand description
Trait for NonZero primitive integers.
This encapsulates trait implementations, constants, and inherent methods that are common among
all of the implementations of NonZero<T>, where T is a PrimitiveInteger.
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::NonZeroPrimitiveInteger;
use core::num::NonZero;
fn bits_and_zeros<T: NonZeroPrimitiveInteger>(n: T) -> (u32, u32, u32) {
(T::BITS, n.leading_zeros(), n.trailing_zeros())
}
assert_eq!(bits_and_zeros(NonZero::new(0b0010_1000u8).unwrap()), (8, 2, 3));
assert_eq!(bits_and_zeros(NonZero::new(1i64).unwrap()), (64, 63, 0));Required Associated Constants§
Required Associated Types§
Sourcetype Integer: PrimitiveInteger<NonZero = Self>
type Integer: PrimitiveInteger<NonZero = Self>
The primitive integer type that this non-zero type wraps.
For core::num::NonZero<T>, this is T.
Required Methods§
Sourcefn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
Multiplies two non-zero integers together. Returns None on overflow.
Sourcefn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
Raises non-zero value to an integer power. Returns None on overflow.
Sourcefn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
Sourcefn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
Sourcefn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together, saturating at the numeric bounds instead of overflowing.
Sourcefn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power, saturating at the numeric bounds instead of overflowing.
Sourcefn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation of self.
Sourceunsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
Creates a non-zero without checking whether the value is non-zero. This results in undefined behavior if the value is zero.
§Safety
The value must not be zero.
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 NonZeroPrimitiveInteger for NonZero<i8>
impl NonZeroPrimitiveInteger for NonZero<i8>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = i8
Source§impl NonZeroPrimitiveInteger for NonZero<i16>
impl NonZeroPrimitiveInteger for NonZero<i16>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = i16
Source§impl NonZeroPrimitiveInteger for NonZero<i32>
impl NonZeroPrimitiveInteger for NonZero<i32>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = i32
Source§impl NonZeroPrimitiveInteger for NonZero<i64>
impl NonZeroPrimitiveInteger for NonZero<i64>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = i64
Source§impl NonZeroPrimitiveInteger for NonZero<i128>
impl NonZeroPrimitiveInteger for NonZero<i128>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = i128
Source§impl NonZeroPrimitiveInteger for NonZero<isize>
impl NonZeroPrimitiveInteger for NonZero<isize>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = isize
Source§impl NonZeroPrimitiveInteger for NonZero<u8>
impl NonZeroPrimitiveInteger for NonZero<u8>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = u8
Source§impl NonZeroPrimitiveInteger for NonZero<u16>
impl NonZeroPrimitiveInteger for NonZero<u16>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = u16
Source§impl NonZeroPrimitiveInteger for NonZero<u32>
impl NonZeroPrimitiveInteger for NonZero<u32>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = u32
Source§impl NonZeroPrimitiveInteger for NonZero<u64>
impl NonZeroPrimitiveInteger for NonZero<u64>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = u64
Source§impl NonZeroPrimitiveInteger for NonZero<u128>
impl NonZeroPrimitiveInteger for NonZero<u128>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.
type Integer = u128
Source§impl NonZeroPrimitiveInteger for NonZero<usize>
impl NonZeroPrimitiveInteger for NonZero<usize>
Source§fn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
See the inherent checked_mul method.
Source§fn checked_pow(self, other: u32) -> Option<Self>
fn checked_pow(self, other: u32) -> Option<Self>
See the inherent checked_pow method.
Source§fn count_ones(self) -> NonZero<u32>
fn count_ones(self) -> NonZero<u32>
See the inherent count_ones method.
Source§fn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See the inherent leading_zeros method.
Source§fn saturating_mul(self, other: Self) -> Self
fn saturating_mul(self, other: Self) -> Self
See the inherent saturating_mul method.
Source§fn saturating_pow(self, other: u32) -> Self
fn saturating_pow(self, other: u32) -> Self
See the inherent saturating_pow method.
Source§fn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See the inherent trailing_zeros method.
Source§unsafe fn new_unchecked(n: Self::Integer) -> Self
unsafe fn new_unchecked(n: Self::Integer) -> Self
See the inherent new_unchecked method.