pub struct NonZero<T>(/* private fields */);
Expand description
Wrapper type for non-zero integers.
Implementations§
Source§impl<T> NonZero<T>
impl<T> NonZero<T>
Sourcepub fn from_be_bytes(bytes: T::Repr) -> CtOption<Self>
pub fn from_be_bytes(bytes: T::Repr) -> CtOption<Self>
Decode from big endian bytes.
Sourcepub fn from_le_bytes(bytes: T::Repr) -> CtOption<Self>
pub fn from_le_bytes(bytes: T::Repr) -> CtOption<Self>
Decode from little endian bytes.
Source§impl NonZero<Limb>
impl NonZero<Limb>
Sourcepub const fn new_unwrap(n: Limb) -> Self
pub const fn new_unwrap(n: Limb) -> Self
Creates a new non-zero limb in a const context. Panics if the value is zero.
In future versions of Rust it should be possible to replace this with
NonZero::new(…).unwrap()
Sourcepub const fn from_u8(n: NonZeroU8) -> Self
pub const fn from_u8(n: NonZeroU8) -> Self
Create a NonZero<Limb>
from a NonZeroU8
(const-friendly)
Sourcepub const fn from_u16(n: NonZeroU16) -> Self
pub const fn from_u16(n: NonZeroU16) -> Self
Create a NonZero<Limb>
from a NonZeroU16
(const-friendly)
Sourcepub const fn from_u32(n: NonZeroU32) -> Self
pub const fn from_u32(n: NonZeroU32) -> Self
Create a NonZero<Limb>
from a NonZeroU32
(const-friendly)
Sourcepub const fn from_u64(n: NonZeroU64) -> Self
Available on 64-bit only.
pub const fn from_u64(n: NonZeroU64) -> Self
Create a NonZero<Limb>
from a NonZeroU64
(const-friendly)
Source§impl<const LIMBS: usize> NonZero<Uint<LIMBS>>
impl<const LIMBS: usize> NonZero<Uint<LIMBS>>
Sourcepub const fn new_unwrap(n: Uint<LIMBS>) -> Self
pub const fn new_unwrap(n: Uint<LIMBS>) -> Self
Creates a new non-zero integer in a const context. Panics if the value is zero.
In future versions of Rust it should be possible to replace this with
NonZero::new(…).unwrap()
Sourcepub const fn from_u8(n: NonZeroU8) -> Self
pub const fn from_u8(n: NonZeroU8) -> Self
Create a NonZero<Uint>
from a NonZeroU8
(const-friendly)
Sourcepub const fn from_u16(n: NonZeroU16) -> Self
pub const fn from_u16(n: NonZeroU16) -> Self
Create a NonZero<Uint>
from a NonZeroU16
(const-friendly)
Sourcepub const fn from_u32(n: NonZeroU32) -> Self
pub const fn from_u32(n: NonZeroU32) -> Self
Create a NonZero<Uint>
from a NonZeroU32
(const-friendly)
Sourcepub const fn from_u64(n: NonZeroU64) -> Self
pub const fn from_u64(n: NonZeroU64) -> Self
Create a NonZero<Uint>
from a NonZeroU64
(const-friendly)
Sourcepub const fn from_u128(n: NonZeroU128) -> Self
pub const fn from_u128(n: NonZeroU128) -> Self
Create a NonZero<Uint>
from a NonZeroU128
(const-friendly)
Source§impl<const LIMBS: usize> NonZero<Int<LIMBS>>
impl<const LIMBS: usize> NonZero<Int<LIMBS>>
Sourcepub const fn abs_sign(&self) -> (NonZero<Uint<LIMBS>>, ConstChoice)
pub const fn abs_sign(&self) -> (NonZero<Uint<LIMBS>>, ConstChoice)
Convert a NonZero<Int>
to its sign and NonZero<Uint>
magnitude.
Source§impl<T> NonZero<T>where
T: ArrayEncoding + Zero,
impl<T> NonZero<T>where
T: ArrayEncoding + Zero,
Sourcepub fn from_be_byte_array(bytes: ByteArray<T>) -> CtOption<Self>
Available on crate feature hybrid-array
only.
pub fn from_be_byte_array(bytes: ByteArray<T>) -> CtOption<Self>
hybrid-array
only.Decode a non-zero integer from big endian bytes.
Sourcepub fn from_le_byte_array(bytes: ByteArray<T>) -> CtOption<Self>
Available on crate feature hybrid-array
only.
pub fn from_le_byte_array(bytes: ByteArray<T>) -> CtOption<Self>
hybrid-array
only.Decode a non-zero integer from big endian bytes.
Trait Implementations§
Source§impl<T> ConditionallySelectable for NonZero<T>where
T: ConditionallySelectable,
impl<T> ConditionallySelectable for NonZero<T>where
T: ConditionallySelectable,
Source§fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
self
and other
if choice == 1
; otherwise,
reassign both unto themselves. Read moreSource§impl<T> ConstantTimeEq for NonZero<T>where
T: ConstantTimeEq,
impl<T> ConstantTimeEq for NonZero<T>where
T: ConstantTimeEq,
Source§impl<'de, T: Deserialize<'de> + Zero> Deserialize<'de> for NonZero<T>
Available on crate feature serde
only.
impl<'de, T: Deserialize<'de> + Zero> Deserialize<'de> for NonZero<T>
serde
only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl DivAssign<&NonZero<BoxedUint>> for Wrapping<BoxedUint>
Available on crate feature alloc
only.
impl DivAssign<&NonZero<BoxedUint>> for Wrapping<BoxedUint>
alloc
only.Source§impl DivAssign<NonZero<BoxedUint>> for Wrapping<BoxedUint>
Available on crate feature alloc
only.
impl DivAssign<NonZero<BoxedUint>> for Wrapping<BoxedUint>
alloc
only.