indexing - Why are all indexes in Rust of type usize? -
rust's std::ops::index<t>
only supports t
being usize
. reason behind this?
also, there no advice "try using usize" when attempt use else, "trait [&'static str]: core::ops::index<u8>
not satisfied" error. maybe because plan support more types t
, delayed doing reason?
rust's
std::ops::index<t>
supportst
beingusize
.
this not true. hashmap
, example, accepts type key type can borrow (so can index hashmap<string, _>
using &str
).
slices allow index them using usize
, container types either pretend be, or are, linear in memory. that's because usize
correct type index them. other type either not able access full potential range of container, or allow indices cannot possibly exist.
people have asked in past adding smaller types slice indexing, backward-incompatible, it's not going happen time soon.
Comments
Post a Comment