yeah rust is not great at this :(( i think you can kinda do it using Pin, but its very annoying. using raw pointers isnt great, cause if you move your object, the pointers will be invalid
Comments
Log in with your Bluesky account to leave a comment
my usual solution when this happens is to just refactor the code to sidestep the issue. if ur reference is into a vec, you can store indices/ranges instead of an actual reference, but its not great
The thing is that it’s not simple at all! It all comes down to rules about when something is allowed to be replaced/moved or not. Once you allow self references, that gets *very* complicated (hence Pin being scary). You’re actually probably better off using a Rc in most cases despite the friction.
Comments