Description
Proposal
My idea constists of making a kind of special trait OnCopy
, which should have a method to update a value of &this pointer, in order to allow struct refer to itself, outer code shouldn't change it, method should be called only by runtime.As addition in such case we would like to have ability to know is this hook created or not(for compiler needs, program logic).
Usage of the trait should be marked explictly #[Derive(OnCopy)]
.
UPD: I meant to have no need to overload it, it just may be called to update self-refs in struct, in time of process of move, e.g should be not overloaded. And implemented automatically
UPD 2: Another variant of the proposed trait is building two derive macroses instead of one. One named like #[Derive(SelfRefBase)]
, and tells compiler that this struct can have self-ref's(Just marker for adding blanket impl. ). Second named like #[Derive(SelfRef)]
, should mark field that refers to object in struct, require it to be a ref
.(via adding it during compile time into static byte array(which indicates which refs in struct should be updated, in order to point to right location))
I've seen the #2613, main difference of these proposals is that there this trait should be marked explictly by user, and not be implemented by one.