Non-borrow std::ops::Index

I once had an issue implementing a Scalar Value String in Rust, where its index operator should return a non-borrow type (the string type itself, not something like &str).

Currently we've only std::ops::Index and std::ops::IndexMut, both of which output &Output. Is it trivial for Rust to support something like std::ops::NonRefIndex?

1 Like

No it’s not trivial. There’s a lots of easy to find prior discussions to find out more about the problems. E.g. here.