Crate zero_based_index

Source
Expand description

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.

Structs§

ZBI
Newtype offering some utility methods for zero-based indices

Traits§

AsZBI
Convenience trait for working with zero-based indices, notably of type usize