pub struct OneIndexed(/* private fields */);
Expand description
Type-safe wrapper for a value whose logical range starts at 1
, for
instance the line or column numbers in a file
Internally this is represented as a NonZeroU32
, this enables some
memory optimizations
Implementations§
source§impl OneIndexed
impl OneIndexed
sourcepub const fn new(value: u32) -> Option<Self>
pub const fn new(value: u32) -> Option<Self>
Creates a non-zero if the given value is not zero.
sourcepub const fn from_zero_indexed(value: u32) -> Self
pub const fn from_zero_indexed(value: u32) -> Self
Construct a new OneIndexed
from a zero-indexed value
sourcepub const fn try_from_zero_indexed(value: usize) -> Result<Self, usize>
pub const fn try_from_zero_indexed(value: usize) -> Result<Self, usize>
Construct a new OneIndexed
from a zero-indexed usize value
sourcepub const fn to_usize(self) -> usize
pub const fn to_usize(self) -> usize
Return the usize value for this OneIndexed
sourcepub const fn to_zero_indexed(self) -> u32
pub const fn to_zero_indexed(self) -> u32
Return the zero-indexed primitive value for this OneIndexed
sourcepub const fn to_zero_indexed_usize(self) -> usize
pub const fn to_zero_indexed_usize(self) -> usize
Return the zero-indexed usize value for this OneIndexed
sourcepub const fn saturating_add(self, rhs: u32) -> Self
pub const fn saturating_add(self, rhs: u32) -> Self
Saturating integer addition. Computes self + rhs
, saturating at
the numeric bounds instead of overflowing.
sourcepub const fn saturating_sub(self, rhs: u32) -> Self
pub const fn saturating_sub(self, rhs: u32) -> Self
Saturating integer subtraction. Computes self - rhs
, saturating
at the numeric bounds instead of overflowing.
Trait Implementations§
source§impl Clone for OneIndexed
impl Clone for OneIndexed
source§fn clone(&self) -> OneIndexed
fn clone(&self) -> OneIndexed
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for OneIndexed
impl Debug for OneIndexed
source§impl Display for OneIndexed
impl Display for OneIndexed
source§impl Hash for OneIndexed
impl Hash for OneIndexed
source§impl Ord for OneIndexed
impl Ord for OneIndexed
source§fn cmp(&self, other: &OneIndexed) -> Ordering
fn cmp(&self, other: &OneIndexed) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for OneIndexed
impl PartialEq for OneIndexed
source§fn eq(&self, other: &OneIndexed) -> bool
fn eq(&self, other: &OneIndexed) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for OneIndexed
impl PartialOrd for OneIndexed
source§fn partial_cmp(&self, other: &OneIndexed) -> Option<Ordering>
fn partial_cmp(&self, other: &OneIndexed) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moreimpl Copy for OneIndexed
impl Eq for OneIndexed
impl StructuralPartialEq for OneIndexed
Auto Trait Implementations§
impl Freeze for OneIndexed
impl RefUnwindSafe for OneIndexed
impl Send for OneIndexed
impl Sync for OneIndexed
impl Unpin for OneIndexed
impl UnwindSafe for OneIndexed
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
Mutably borrows from an owned value. Read more