pub struct ZBI<T>(pub T);
Expand description

Newtype offering some utility methods for zero-based indices

Tuple Fields

0: T

Implementations

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

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.