devela::all

Type Alias NonZeroU16

1.28.0 · Source
pub type NonZeroU16 = NonZero<u16>;
Expand description

core An unsigned integer that is known not to equal zero.

Re-exported from core::num:: .


A u16 that is known not to equal zero.

This enables some memory layout optimization. For example, Option<NonZeroU16> is the same size as u16:

use std::mem::size_of;
assert_eq!(size_of::<Option<core::num::NonZeroU16>>(), size_of::<u16>());

§Layout

NonZeroU16 is guaranteed to have the same layout and bit validity as u16 with the exception that 0 is not a valid instance. Option<NonZeroU16> is guaranteed to be compatible with u16, including in FFI.

Thanks to the null pointer optimization, NonZeroU16 and Option<NonZeroU16> are guaranteed to have the same size and alignment:

use std::num::NonZeroU16;

assert_eq!(size_of::<NonZeroU16>(), size_of::<Option<NonZeroU16>>());
assert_eq!(align_of::<NonZeroU16>(), align_of::<Option<NonZeroU16>>());

Aliased Type§

struct NonZeroU16(/* private fields */);

Trait Implementations§

Source§

impl BitSized<16> for NonZeroU16

Source§

const BIT_SIZE: usize = _

The bit size of this type (only the relevant data part, without padding). Read more
Source§

const MIN_BYTE_SIZE: usize = _

The rounded up byte size for this type. Read more
Source§

fn bit_size(&self) -> usize

Returns the bit size of this type (only the relevant data part, without padding). Read more
Source§

fn min_byte_size(&self) -> usize

Returns the rounded up byte size for this type. Read more
Source§

impl Num for NonZeroU16

Available on crate feature _int_u16 only.
Source§

fn num_set_one(&mut self) -> Result<()>

§Features

Makes use of the unsafe_niche feature if enabled.

Source§

type Inner = u16

The internal representation of this numeric type.
Source§

type Out = NonZero<u16>

The output type for operations.
Source§

type Rhs = NonZero<u16>

The right hand side type for operations.
Source§

fn num_into(self) -> Self::Inner

Returns the inner self representation.
Source§

fn num_from(from: Self::Inner) -> Result<Self>

Returns Self if given a valid value.
Source§

fn num_from_ref(from: &Self::Inner) -> Result<Self>

Returns Self if given a valid &value.
Source§

fn num_set(&mut self, value: Self::Inner) -> Result<()>

Sets self to the given valid value.
Source§

fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>

Sets self to the given valid &value.
Source§

fn num_is_zero(&self) -> Result<bool>

Returns true if self is zero.
Source§

fn num_is_one(&self) -> Result<bool>

Returns true if self is one.
Source§

fn num_get_zero() -> Result<Self>

Returns the number zero.
Source§

fn num_get_one() -> Result<Self>

Returns the number one.
Source§

fn num_set_zero(&mut self) -> Result<()>

Sets self to 0.
Source§

fn num_mul(self, other: Self) -> Result<Self::Out>

Computes self * rhs (multiplication).
Source§

fn num_ref_mul(&self, other: &Self) -> Result<Self::Out>

Like num_mul but takes the arguments by reference.
Source§

fn num_ref_mul_assign(&mut self, other: &Self) -> Result<()>

Computes &mut self *= rhs; (multiplication).
Source§

fn num_add(self, other: Self) -> Result<Self::Out>

Computes self + rhs (addition).
Source§

fn num_ref_add(&self, other: &Self) -> Result<Self::Out>

Like num_add but takes the arguments by reference.
Source§

fn num_ref_add_assign(&mut self, other: &Self) -> Result<()>

Computes &mut self += rhs; (addition).
Source§

fn num_sub(self, other: Self) -> Result<Self::Out>

Computes self - rhs (subtraction).
Source§

fn num_ref_sub(&self, other: &Self) -> Result<Self::Out>

Like num_sub but takes the arguments by reference.
Source§

fn num_ref_sub_assign(&mut self, other: &Self) -> Result<()>

Computes &mut self -= rhs; (subtraction).
Source§

fn num_div(self, other: Self) -> Result<Self::Out>

Computes self / rhs (division).
Source§

fn num_ref_div(&self, other: &Self) -> Result<Self::Out>

Like num_div but takes the arguments by reference.
Source§

fn num_ref_div_assign(&mut self, other: &Self) -> Result<()>

Computes &mut self /= rhs; (division).
Source§

fn num_rem(self, other: Self) -> Result<Self::Out>

Computes self % rhs (remainder).
Source§

fn num_ref_rem(&self, other: &Self) -> Result<Self::Out>

Like num_rem but takes the arguments by reference.
Source§

fn num_ref_rem_assign(&mut self, other: &Self) -> Result<()>

Computes &mut self %= rhs; (remainder).
Source§

fn num_abs(self) -> Result<Self>

Computes |self| (absolute value).
Source§

fn num_ref_abs(&self) -> Result<Self>

Like num_abs but takes the arguments by reference.
Source§

fn num_neg(self) -> Result<Self::Out>
where Self: Sized,

Computes -self (additive inverse).
Source§

fn num_ref_neg(&self) -> Result<Self::Out>

Like num_neg but takes the arguments by reference.