In another post I discussed some ideas I came up with.
Basically, I think Rust need a mechanism to say "whenever you send this value to somewhere else, you have to send that value as well". This guarantees, whenever we move the "weak reference", the referee is also moved or at least visible for the compiler to generate adjust code.
Without this ability (I think it is fair to say that no existing languages provide such checking in compile time), we will need to use unsafe code to ensure the invariant above. Then we can use the Access trait to achieve this.
(My Access
trait is similar to Index/IndexMut
, but they are different: it allows to return something that is not a reference. So you can return something like Option<&T>
or Result<&T,E>
. Also, its self
is the index, not the container)