3 ms·
Any plans on adding Box, Rc, RefCell, and the differences thereof? That's the thing that trips me up the most right now.
by RedHotRiplets 7y ago
Any plans on adding Box, Rc, RefCell, and the differences thereof? That's the thing that trips me up the most right now.
- steveklabnik 7y agoTo 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.