In C++ I can write a class that in its constructor registers inserts its
this pointer into a global container, on destruction removes the pointer from the global container, and on move changes the value stored inside the global container. Sometimes this is useful for debugging and sometimes it is useful for performance hacks.
I know Rust doesn't have move constructors or move assignment operators and generally assumes that moves can always be achieved by shallow byte copying. I also understand that in general unsafe Rust code can rely on this property, which is a barrier to having move constructors and move assignment operators as a general language feature. I also know that in rust drop is not guaranteed to run because of things like reference cycles.
My question is is there some way to achieve why I'm able to achieve in C++, so long as I am okay with the fact that I am going to have to manually audit any unsafe code dealing with this particular
T and manually convince myself that where it is used drop will run. I understand these are giant caveats and I am okay with them for my project (I'm hoping this prevents this thread from derailing into people lecturing that I shouldn't want what I want).
My current plan is to never give users direct access to T and only give them references. Users will have to ask a central registry to create Ts under the covers on their behalf, and then be able to move them around only by calling an explicit move method on the registry and providing it handles. However, this is extremely limiting, and prevents me sometimes from being able to get the memory layout that I want which is important for performance (I can't just put a T in a struct next to other fields I know will already be hot when I want to access the T, the best I can do is put a handle to the T instance there).