pub struct NonMaxU32(NonZeroU32);
Expand description
An unsigned 32-bit value known not to be u32::MAX
.
A NonMaxU32
value can represent any value in the range 0 .. u32::MAX - 1
, and an Option<NonMaxU32>
is still a 32-bit value. In other words,
NonMaxU32
is just like NonZeroU32
, except that a different value is
missing from the full u32
range.
Since zero is a very useful value in indexing, NonMaxU32
is more useful
for representing indices than NonZeroU32
.
NonMaxU32
values and Option<NonMaxU32>
values both occupy 32 bits.
§Serialization and Deserialization
When the appropriate Cargo features are enabled, NonMaxU32
implements
[serde::Serialize
] and [serde::Deserialize
] in the natural way, as the
integer value it represents. For example, serializing
NonMaxU32::new(0).unwrap()
as JSON or RON yields the string "0"
. This is
the case despite NonMaxU32
’s implementation, described below.
§Implementation
Although this should not be observable to its users, a NonMaxU32
whose
value is n
is a newtype around a NonZeroU32
whose value is n + 1
.
This way, the range of values that NonMaxU32
can represent, `0..=u32::MAX
- 1
, is mapped to the range
1..=u32::MAX, which is the range that [
NonZeroU32] can represent. (And conversely, since [
u32] addition wraps around, the value unrepresentable in
NonMaxU32, [
u32::MAX], becomes the value unrepresentable in [
NonZeroU32],
0`.)
Tuple Fields§
§0: NonZeroU32
Implementations§
source§impl NonMaxU32
impl NonMaxU32
sourcepub const unsafe fn new_unchecked(n: u32) -> NonMaxU32
pub const unsafe fn new_unchecked(n: u32) -> NonMaxU32
sourcepub const unsafe fn from_usize_unchecked(index: usize) -> Self
pub const unsafe fn from_usize_unchecked(index: usize) -> Self
pub fn checked_add(self, n: u32) -> Option<Self>
Trait Implementations§
source§impl Ord for NonMaxU32
impl Ord for NonMaxU32
source§impl PartialOrd for NonMaxU32
impl PartialOrd for NonMaxU32
impl Copy for NonMaxU32
impl Eq for NonMaxU32
impl StructuralPartialEq for NonMaxU32
Auto Trait Implementations§
impl Freeze for NonMaxU32
impl RefUnwindSafe for NonMaxU32
impl Send for NonMaxU32
impl Sync for NonMaxU32
impl Unpin for NonMaxU32
impl UnwindSafe for NonMaxU32
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.