Feature Request: add a trait the same as std::ops::Index but returns an object rather than a reference

Generally, the indexing syntax is useful for code clarity in that it returns a view (reference) into the indexed object.

What benefit (other than terseness) do you get by returning an owned 'static value from indexing? That isn't provided by just a .get()?

Additionally, what happens if you implement both Index and MyIndex? If you can't, how is that enforced?

Previously:

(Wow I've argued this point a fair number of times... indexing returning a custom type seems like an obvious extension, it just runs into a whole thorny bush of issues once you start digging into the implications. Maybe I should write up some lang design notes to this effect...)

5 Likes