| Crates.io | into_index |
| lib.rs | into_index |
| version | 0.2.0 |
| created_at | 2024-04-30 14:28:58.36622+00 |
| updated_at | 2025-04-04 09:42:31.78254+00 |
| description | Helper traits allowing indexing into vectors and similar types by other types than `usize` |
| homepage | |
| repository | https://git.pipapo.org/cehteh/into_index.git |
| max_upload_size | |
| id | 1225069 |
| size | 8,075 |
IntoIndexSometimes 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 AtMutFurther 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.
use into_index::{IntoIndex, At};
let v = vec![1,2,3];
assert_eq!(*v.at(1u8), 2);