#indices

zero_based_index

Newtype offering some utility methods for zero-based indices

4 releases

0.2.2 Oct 14, 2022
0.2.1 Oct 14, 2022
0.1.1 Jan 11, 2022
0.1.0 Jan 11, 2022

#1514 in Math


Used in get_len_base_10_as_usize

MIT/Apache

10KB

crates.io crates.io crates.io

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

  • len for length;
  • int for integer.
  • zbi for zero-based index.

Examples

Base case

use zero_based_index::ZBI;

let zbi = ZBI(2usize);
assert_eq!(zbi.to_len(), Some(3));

Base case with zero_based_index::AsZBI

use zero_based_index::{ZBI, AsZBI};

let zbi = 2.as_zbi();
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);

Features

  • Check the list of feature flags here.
  • Learn about features in general here.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~235KB