MyWrapper<T> does the internal de-referencing to the entries in the arena (basically its a *const T).
Switching Box an MyWrapper doesn't solve the problem. Code that correctly inserts and removes elements is written.
The idea is to build a collection that can be both accessed by index and by hashing. Therefore, I'd like to give users of MyStruct an API similar to a normal HashMap, e.g.
The obvious way would be to impl<T, Q> Borrow<Q> for MyWrapper<T>. However, this conflicts with the impl<T> Borrow<T> for T in the std/core crate. I also rely on the Borrow<Q> bound so going for a simpler signature with only key: &T is not an option.
Has anyone a solution or at least some inspiration for me?
This worked! Thank you very much! I don't think I could've come up with this solution on my own.
However, I'm not sure if I understood the from_ref() function correctly. For me it looks like a &BorrowWrapper<T> is actually only a type level construct for a &T which is required to implement the Borrow<Q> outside of the restrictions of the std/core crate.
By using repr(transparent) we've created a type that has the same memory representation as the inner type, but at the type level it's different from the inner type. That allows us to implement the trait we need as the compiler can prove the blanket impl will never apply, unless we implement traits matching the blanket constraints in our own crate, which we don't.