into_index 0.2.0

Helper traits allowing indexing into vectors and similar types by other types than `usize`
Documentation
  • Coverage
  • 100%
    11 out of 11 items documented6 out of 10 items with examples
  • Size
  • Source code size: 7.58 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.33 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • cehteh

IntoIndex

Sometimes it is more convenient to use another type than usize to calculate and store indices. This crate provides an IntoIndex trait that can be used to convert any type into an usize. For types that implement TryInto<usize> this is already implented. Naturally some of these conversions are fallible,​ the into_index() method may panic in this case. A try_into_index() method that returns a Result for handling such errors are available as well.

At and AtMut

Further the At and AtMut traits use IntoIndex for providing indexing without the associated Output type that is required for the Index and IndexMut traits. These are implented for all types implementing AsRef<[T]> and AsMut<[T]> respectively. This allows for indexing into slices, vectors, arrays and other types that implement these traits.

Example

use into_index::{IntoIndex, At};
let v = vec![1,2,3];

assert_eq!(*v.at(1u8), 2);