Replying to Avatar Mike Dilger ☑️

The basics are easy to understand, but what is tricky is interpreting what the compiler is actually saying. The basics are just that if you borrow something, you must ensure that the owning variable stays alive during the entire lifetime of the borrow.... otherwise it will be freed and the borrowing reference will point at memory that isn't safe anymore. But the details about how to do this, and what the fuck the compiler just said, that is where the nightmare arises.

I have to admit I've avoided using Rc and RefCell and gone straight to Arc and RwLock instead because those work in more cases and I can't be bothered with the single thread cases anymore.

And I usually only have to reference lifetimes if a structure has borrowed data. Borrowed parameters in functions giving borrowed return values don't need explicit lifetimes anymore.

Avatar
Daniel Wigton 1y ago

Yes! Arc all the things! Because you know whatever you want to pass contains an object from a library that does not impl clone.

Reply to this note

Please Login to reply.

Discussion

No replies yet.