Struct zero_based_index::ZBI
source · [−]pub struct ZBI<T>(pub T);
Expand description
Newtype offering some utility methods for zero-based indices
Tuple Fields
0: T
Implementations
sourceimpl ZBI<usize>
impl ZBI<usize>
sourcepub const fn to_len(&self) -> Option<usize>
pub const fn to_len(&self) -> Option<usize>
If the cardinality of the
closed
integer interval
from 0 to the stored value fits into usize, returns that cardinality
as Some
variant of Option<usize>. Otherwise (when
happens integer overflow),
the returned value is None
.
Using mathematical notation,
Examples
Base case
use zero_based_index::ZBI;
let zbi = ZBI(2usize);
assert_eq!(zbi.to_len(), Some(3));
Corner case
use zero_based_index::ZBI;
let zbi = ZBI(usize::MAX);
assert_eq!(zbi.to_len(), None);
Auto Trait Implementations
impl<T> RefUnwindSafe for ZBI<T>where
T: RefUnwindSafe,
impl<T> Send for ZBI<T>where
T: Send,
impl<T> Sync for ZBI<T>where
T: Sync,
impl<T> Unpin for ZBI<T>where
T: Unpin,
impl<T> UnwindSafe for ZBI<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more