pub struct NonNegative<T>(/* private fields */);Expand description
Proof that a signed value is >= 0.
Implementations§
Source§impl NonNegative<i8>
impl NonNegative<i8>
Source§impl NonNegative<i16>
impl NonNegative<i16>
Source§impl NonNegative<i32>
impl NonNegative<i32>
Source§impl NonNegative<i64>
impl NonNegative<i64>
Source§impl NonNegative<i128>
impl NonNegative<i128>
Source§impl NonNegative<isize>
impl NonNegative<isize>
Source§impl NonNegative<i8>
impl NonNegative<i8>
Sourcepub const unsafe fn new_unchecked(value: i8) -> Self
pub const unsafe fn new_unchecked(value: i8) -> Self
§Safety
value must be >= 0.
Sourcepub fn from_ref(value: &i8) -> Option<&Self>
pub fn from_ref(value: &i8) -> Option<&Self>
Zero-cost borrowed proof (repr(transparent) reinterpret).
Sourcepub const fn to_unsigned(self) -> u8
pub const fn to_unsigned(self) -> u8
Infallible cast to the unsigned counterpart — the value is >= 0
so the bit pattern is preserved; no Option, no panic.
Sourcepub const fn isqrt(self) -> i8
pub const fn isqrt(self) -> i8
isqrt is total on a non-negative value (the inherent signed
isqrt would otherwise panic on negatives).
Sourcepub const fn into_nonmin(self) -> NonMin<i8>
pub const fn into_nonmin(self) -> NonMin<i8>
NonNegative ⊂ NonMin (>= 0, and MIN < 0, so != MIN) —
narrows with no recheck so it can feed total neg/abs/division.
Source§impl NonNegative<i16>
impl NonNegative<i16>
Sourcepub const unsafe fn new_unchecked(value: i16) -> Self
pub const unsafe fn new_unchecked(value: i16) -> Self
§Safety
value must be >= 0.
Sourcepub fn from_ref(value: &i16) -> Option<&Self>
pub fn from_ref(value: &i16) -> Option<&Self>
Zero-cost borrowed proof (repr(transparent) reinterpret).
Sourcepub const fn to_unsigned(self) -> u16
pub const fn to_unsigned(self) -> u16
Infallible cast to the unsigned counterpart — the value is >= 0
so the bit pattern is preserved; no Option, no panic.
Sourcepub const fn isqrt(self) -> i16
pub const fn isqrt(self) -> i16
isqrt is total on a non-negative value (the inherent signed
isqrt would otherwise panic on negatives).
Sourcepub const fn into_nonmin(self) -> NonMin<i16>
pub const fn into_nonmin(self) -> NonMin<i16>
NonNegative ⊂ NonMin (>= 0, and MIN < 0, so != MIN) —
narrows with no recheck so it can feed total neg/abs/division.
Source§impl NonNegative<i32>
impl NonNegative<i32>
Sourcepub const unsafe fn new_unchecked(value: i32) -> Self
pub const unsafe fn new_unchecked(value: i32) -> Self
§Safety
value must be >= 0.
Sourcepub fn from_ref(value: &i32) -> Option<&Self>
pub fn from_ref(value: &i32) -> Option<&Self>
Zero-cost borrowed proof (repr(transparent) reinterpret).
Sourcepub const fn to_unsigned(self) -> u32
pub const fn to_unsigned(self) -> u32
Infallible cast to the unsigned counterpart — the value is >= 0
so the bit pattern is preserved; no Option, no panic.
Sourcepub const fn isqrt(self) -> i32
pub const fn isqrt(self) -> i32
isqrt is total on a non-negative value (the inherent signed
isqrt would otherwise panic on negatives).
Sourcepub const fn into_nonmin(self) -> NonMin<i32>
pub const fn into_nonmin(self) -> NonMin<i32>
NonNegative ⊂ NonMin (>= 0, and MIN < 0, so != MIN) —
narrows with no recheck so it can feed total neg/abs/division.
Source§impl NonNegative<i64>
impl NonNegative<i64>
Sourcepub const unsafe fn new_unchecked(value: i64) -> Self
pub const unsafe fn new_unchecked(value: i64) -> Self
§Safety
value must be >= 0.
Sourcepub fn from_ref(value: &i64) -> Option<&Self>
pub fn from_ref(value: &i64) -> Option<&Self>
Zero-cost borrowed proof (repr(transparent) reinterpret).
Sourcepub const fn to_unsigned(self) -> u64
pub const fn to_unsigned(self) -> u64
Infallible cast to the unsigned counterpart — the value is >= 0
so the bit pattern is preserved; no Option, no panic.
Sourcepub const fn isqrt(self) -> i64
pub const fn isqrt(self) -> i64
isqrt is total on a non-negative value (the inherent signed
isqrt would otherwise panic on negatives).
Sourcepub const fn into_nonmin(self) -> NonMin<i64>
pub const fn into_nonmin(self) -> NonMin<i64>
NonNegative ⊂ NonMin (>= 0, and MIN < 0, so != MIN) —
narrows with no recheck so it can feed total neg/abs/division.
Source§impl NonNegative<i128>
impl NonNegative<i128>
Sourcepub const unsafe fn new_unchecked(value: i128) -> Self
pub const unsafe fn new_unchecked(value: i128) -> Self
§Safety
value must be >= 0.
Sourcepub fn from_ref(value: &i128) -> Option<&Self>
pub fn from_ref(value: &i128) -> Option<&Self>
Zero-cost borrowed proof (repr(transparent) reinterpret).
Sourcepub const fn to_unsigned(self) -> u128
pub const fn to_unsigned(self) -> u128
Infallible cast to the unsigned counterpart — the value is >= 0
so the bit pattern is preserved; no Option, no panic.
Sourcepub const fn isqrt(self) -> i128
pub const fn isqrt(self) -> i128
isqrt is total on a non-negative value (the inherent signed
isqrt would otherwise panic on negatives).
Sourcepub const fn into_nonmin(self) -> NonMin<i128>
pub const fn into_nonmin(self) -> NonMin<i128>
NonNegative ⊂ NonMin (>= 0, and MIN < 0, so != MIN) —
narrows with no recheck so it can feed total neg/abs/division.
Source§impl NonNegative<isize>
impl NonNegative<isize>
Sourcepub const unsafe fn new_unchecked(value: isize) -> Self
pub const unsafe fn new_unchecked(value: isize) -> Self
§Safety
value must be >= 0.
Sourcepub fn from_ref(value: &isize) -> Option<&Self>
pub fn from_ref(value: &isize) -> Option<&Self>
Zero-cost borrowed proof (repr(transparent) reinterpret).
Sourcepub const fn to_unsigned(self) -> usize
pub const fn to_unsigned(self) -> usize
Infallible cast to the unsigned counterpart — the value is >= 0
so the bit pattern is preserved; no Option, no panic.
Sourcepub const fn isqrt(self) -> isize
pub const fn isqrt(self) -> isize
isqrt is total on a non-negative value (the inherent signed
isqrt would otherwise panic on negatives).
Sourcepub const fn into_nonmin(self) -> NonMin<isize>
pub const fn into_nonmin(self) -> NonMin<isize>
NonNegative ⊂ NonMin (>= 0, and MIN < 0, so != MIN) —
narrows with no recheck so it can feed total neg/abs/division.
Trait Implementations§
Source§impl<T: Clone> Clone for NonNegative<T>
impl<T: Clone> Clone for NonNegative<T>
Source§fn clone(&self) -> NonNegative<T>
fn clone(&self) -> NonNegative<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<T: Copy> Copy for NonNegative<T>
Source§impl<T: Debug> Debug for NonNegative<T>
impl<T: Debug> Debug for NonNegative<T>
impl<T: Eq> Eq for NonNegative<T>
Source§impl<T: PartialEq> PartialEq for NonNegative<T>
impl<T: PartialEq> PartialEq for NonNegative<T>
Source§fn eq(&self, other: &NonNegative<T>) -> bool
fn eq(&self, other: &NonNegative<T>) -> bool
self and other values to be equal, and is used by ==.impl<T: PartialEq> StructuralPartialEq for NonNegative<T>
Source§impl TryFrom<i8> for NonNegative<i8>
Checked construction by value; mirrors NonNegative::new.
impl TryFrom<i8> for NonNegative<i8>
Checked construction by value; mirrors NonNegative::new.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<i16> for NonNegative<i16>
Checked construction by value; mirrors NonNegative::new.
impl TryFrom<i16> for NonNegative<i16>
Checked construction by value; mirrors NonNegative::new.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<i32> for NonNegative<i32>
Checked construction by value; mirrors NonNegative::new.
impl TryFrom<i32> for NonNegative<i32>
Checked construction by value; mirrors NonNegative::new.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<i64> for NonNegative<i64>
Checked construction by value; mirrors NonNegative::new.
impl TryFrom<i64> for NonNegative<i64>
Checked construction by value; mirrors NonNegative::new.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<i128> for NonNegative<i128>
Checked construction by value; mirrors NonNegative::new.
impl TryFrom<i128> for NonNegative<i128>
Checked construction by value; mirrors NonNegative::new.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<isize> for NonNegative<isize>
Checked construction by value; mirrors NonNegative::new.
impl TryFrom<isize> for NonNegative<isize>
Checked construction by value; mirrors NonNegative::new.