Struct beetle_nonzero::NonZero

source ·
pub struct NonZero<T: PrimInt + Integer> { /* private fields */ }
Expand description

An integer that is known to not equal zero.

Implementations§

source§

impl<T> NonZero<T>
where T: PrimInt + Integer,

source

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

Returns a new NonZero<T> if value is nonzero

source

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

Returns a new NonZero without checking that the provided value is nonzero.

§Safety

value must be known to be nonzero

source

pub const fn get(self) -> T

A copy of the nonzero value

source

pub fn is_even(self) -> bool

Whether the nonzero integer is even

source

pub fn is_odd(self) -> bool

Whether the nonzero integer is odd

source

pub fn set(&mut self, value: T) -> bool

Sets self.value using the provided value. Only succeeds if the value provided was nonzero. Returns whether the operation succeeded.

source

pub unsafe fn set_unchecked(&mut self, value: T)

Sets the internal value of the nonzero integer. If the value equals zero, this panics.

§Safety

value must be known to be nonzero

source

pub fn map(self, f: impl Fn(T) -> T) -> Option<Self>

Applies a function to the inner value and returns a NonZero if the result was nonzero.

source

pub unsafe fn map_unchecked(self, f: fn(_: T) -> T) -> Self

Applies a function to the inner value and returns a NonZero if the result was nonzero.

§Safety

f must return a nonzero integer

source

pub fn trailing_zeros(self) -> u32

Returns the number of trailing zeros in the binary representation of the nonzero integer

source§

impl<T> NonZero<T>
where T: PrimInt + Integer + Shr<u32, Output = T>,

source

pub fn without_trailing_zeros(self) -> Self

Returns the number of trailing zeros in the binary representation of the nonzero integer

Trait Implementations§

source§

impl<T: Clone + PrimInt + Integer> Clone for NonZero<T>

source§

fn clone(&self) -> NonZero<T>

Returns a copy 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<T: Debug + PrimInt + Integer> Debug for NonZero<T>

source§

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

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

impl<T> Display for NonZero<T>
where T: PrimInt + Integer + Display,

source§

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

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

impl From<NonZero<u128>> for NonZero<u128>

source§

fn from(value: NonZeroU128) -> Self

Converts to this type from the input type.
source§

impl From<NonZero<u16>> for NonZero<u16>

source§

fn from(value: NonZeroU16) -> Self

Converts to this type from the input type.
source§

impl From<NonZero<u32>> for NonZero<u32>

source§

fn from(value: NonZeroU32) -> Self

Converts to this type from the input type.
source§

impl From<NonZero<u64>> for NonZero<u64>

source§

fn from(value: NonZeroU64) -> Self

Converts to this type from the input type.
source§

impl From<NonZero<u8>> for NonZero<u8>

source§

fn from(value: NonZeroU8) -> Self

Converts to this type from the input type.
source§

impl From<NonZero<usize>> for NonZero<usize>

source§

fn from(value: NonZeroUsize) -> Self

Converts to this type from the input type.
source§

impl<T: Ord + PrimInt + Integer> Ord for NonZero<T>

source§

fn cmp(&self, other: &NonZero<T>) -> 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 + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq + PrimInt + Integer> PartialEq for NonZero<T>

source§

fn eq(&self, other: &NonZero<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd + PrimInt + Integer> PartialOrd for NonZero<T>

source§

fn partial_cmp(&self, other: &NonZero<T>) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: Copy + PrimInt + Integer> Copy for NonZero<T>

source§

impl<T: Eq + PrimInt + Integer> Eq for NonZero<T>

source§

impl<T: PrimInt + Integer> StructuralPartialEq for NonZero<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for NonZero<T>
where T: RefUnwindSafe,

§

impl<T> Send for NonZero<T>
where T: Send,

§

impl<T> Sync for NonZero<T>
where T: Sync,

§

impl<T> Unpin for NonZero<T>
where T: Unpin,

§

impl<T> UnwindSafe for NonZero<T>
where T: UnwindSafe,

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> 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.