zero_based_index 0.1.0

Newtype offering some utility methods for zero-based indices.
Documentation

Newtype offering some utility methods for zero-based indices

In order to keep the lengths of method names reasonable, several abbreviations have been used, namely

Examples

Base case

use zero_based_index::ZeroBasedIndex;

let zbi = ZeroBasedIndex::<usize>(2);
assert_eq!(zbi.try_get_len_of_closed_int_intvl_from_0(), Some(3));

Base case with zero_based_index::AsZeroBasedIndex

use zero_based_index::{ZeroBasedIndex, AsZeroBasedIndex};

let zbi = 2.as_zero_based_index();
assert_eq!(zbi.try_get_len_of_closed_int_intvl_from_0(), Some(3));

Corner case

use zero_based_index::ZeroBasedIndex;

let zbi = ZeroBasedIndex::<usize>(usize::MAX);
assert_eq!(zbi.try_get_len_of_closed_int_intvl_from_0(), None);

Unchecked math

With unchecked_math feature, one can also get access to unsafe superpowers.

License