Help getting started with converting c project

Owning something means you're responsible for destroying it.

Mutating something requires that you have unique access to it (i.e. the inverse of the "Shared" column in that table).

The exception to this is "interior mutability", which is effectively the escape hatch for when you need both shared access and mutability. Types that have interior mutability are referred to as "cells" and/or "locks": Cell, RefCell, RwLock, Mutex, etc. It's up to those types to ensure mutation of their interior is done safely, and that's mostly done by some kind of locking to keep other parts of the code from accessing the interior during mutation.

Sure. Weak specifies the ownership semantics you want, RefCell specifies the interior mutability semantics you want. It's like building stuff with LEGO. Sure, it could be a single type, but then you'd need a type for every possible combination of types, which would arguably be a whole lot worse.

3 Likes