Re:Rust Language Cheat Sheet
by steveklabnik on Monday August 05, 2019 @12:19PM
(#20615337)
To give you a quick summary:
Box is (mostly) used in two specific circumstances: when you want to have ownership of something that lives longer than a single function, and to create heterogeneous lists of things (a "trait object").
Rc is used when you need multiple ownership of something, and you're not going to be sharing those things between threads.
RefCell is a type that moves the borrow checker to runtime; it's useful when you're trying to mutate something, and Rust's static checking can't tell that it's okay. If you mess it up, you'll get a panic. This often happens in combination with Rc, since Rc makes something have multiple owners.
Box is (mostly) used in two specific circumstances: when you want to have ownership of something that lives longer than a single function, and to create heterogeneous lists of things (a "trait object").
Rc is used when you need multiple ownership of something, and you're not going to be sharing those things between threads.
RefCell is a type that moves the borrow checker to runtime; it's useful when you're trying to mutate something, and Rust's static checking can't tell that it's okay. If you mess it up, you'll get a panic. This often happens in combination with Rc, since Rc makes something have multiple owners.