pub struct OneBasedU128(/* private fields */);Expand description
Represents 1-based index of u128.
To describe configuration by humans, often 1-based index is easier than 0-based to understand.
On the other hand, 0-based index is easier to use in the programming.
Also, it’s quite hard to track if the index is 0-based or 1-based.
$name provides ergonomics to handle user provided 1-baed index safely.
// Creates from 1-based index
let v = OneBasedU128::from_one_based(5)?;
assert_eq!(v.as_zero_based(), 4);
// Creates from 0-based index
let v = OneBasedU128::from_zero_based(0)?;
assert_eq!(v.as_one_based().get(), 1);Implementations§
Source§impl OneBasedU128
 
impl OneBasedU128
Sourcepub fn from_one_based(v: u128) -> Result<Self, OneBasedError>
 
pub fn from_one_based(v: u128) -> Result<Self, OneBasedError>
Creates $name from 1-based index value.
Returns error if the given index is zero.
Sourcepub fn from_one_based_nonzero(v: NonZeroU128) -> Self
 
pub fn from_one_based_nonzero(v: NonZeroU128) -> Self
Creates $name from 1-based index value as [$nonzerotype].
This will always succeed.
Sourcepub fn from_zero_based(v: u128) -> Result<Self, OneBasedError>
 
pub fn from_zero_based(v: u128) -> Result<Self, OneBasedError>
Creates $name from 0-based index value.
Returns error if the given index is MAX value,
as that would case overflow when converted to 1-based.
Sourcepub fn as_zero_based(&self) -> u128
 
pub fn as_zero_based(&self) -> u128
Returns regular 0-based index.
Sourcepub fn as_one_based(&self) -> NonZeroU128
 
pub fn as_one_based(&self) -> NonZeroU128
Returns 1-based index.
Trait Implementations§
Source§impl Clone for OneBasedU128
 
impl Clone for OneBasedU128
Source§fn clone(&self) -> OneBasedU128
 
fn clone(&self) -> OneBasedU128
Returns a duplicate 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 OneBasedU128
 
impl Debug for OneBasedU128
Source§impl Display for OneBasedU128
 
impl Display for OneBasedU128
Source§impl FromStr for OneBasedU128
 
impl FromStr for OneBasedU128
Source§impl Ord for OneBasedU128
 
impl Ord for OneBasedU128
Source§fn cmp(&self, other: &OneBasedU128) -> Ordering
 
fn cmp(&self, other: &OneBasedU128) -> 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 OneBasedU128
 
impl PartialEq for OneBasedU128
Source§impl PartialOrd for OneBasedU128
 
impl PartialOrd for OneBasedU128
impl Copy for OneBasedU128
impl Eq for OneBasedU128
impl StructuralPartialEq for OneBasedU128
Auto Trait Implementations§
impl Freeze for OneBasedU128
impl RefUnwindSafe for OneBasedU128
impl Send for OneBasedU128
impl Sync for OneBasedU128
impl Unpin for OneBasedU128
impl UnwindSafe for OneBasedU128
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