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> supports t being usize.

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

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -