2 ms·
I'm confused; in Rust, you use Box when you want a value to escape the function. That's the whole point of Box! Likewise I can't think of any situation where yo
by kibwen 8y ago
I'm confused; in Rust, you use Box when you want a value to escape the function. That's the whole point of Box! Likewise I can't think of any situation where you'd ever want to construct a value in an Rc without that value escaping somehow, because in a single scope you're better off just handing out shared references (I think you may be confusing Rc with RefCell, since they are often used together and RefCell can be useful within a single scope--but note that RefCell never allocates). You have no need to cleverly promote these things to the stack because nobody is using them for data that they don't want to live on the heap; you have to go out of your way to use them! :)