The simple answer I would give would be: use references when you can. Unfortunately, understanding when you can depends on getting a deeper understanding of the borrow checker, and by that point, I would guess a cheat sheet would be less useful. However, some simple explanations might help.
- The simple case is where you have a clear owner, and references are passed down the stack to functions that you call. This case works clearly for just references.
- When you have the same clear ownership but the item is either "large", or of non-determined size, you may need a
Box
. Still a single owner, with possible stack-based borrowing.
- When ownership isn't clearly in a tree,
Rc
or Arc
would be appropriate (with something like a Mutex
for sharing).
The other things mentioned (Ref
, RefMut
) are specifically about borrows of the thing contained in a RefCell
. Cell
and RefCell
are containers that are mutable.
I would say, start by trying to just have your item owned, and using borrowed references to pass it around. If you do need sharing, look into Rc
or Arc
. If that still doesn't work, consider the other things.
Again, though, the Rust Book's description is very good, and you kind of have to get an understanding of borrowing to get a gut feeling of what to use anyway.