What's the point?

Okay, so what's this actually good for? We could have just used a mutable variable, and produced the same result with less overhead. Cell (and RefCell) are mostly for use with Rc and similar data types. The Rc type follows Rust's normal rules about mutability, and since it's meant to be a mechanism for accessing a shared data value in many places, that means that the shared value must be immutable.

Unless that value is a Cell or RefCell containing the real shared value.

The Cell or RefCell ensures that only one block of code at a time actually modifies the shared value, but any of the blocks that have access to it through a clone of the Rc have the ability to do so.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.218.226