> module
std::cell
shared mutable values
use std::cell; in the browser
std::cell provides a Cell type for sharing mutable state across closures and threads. A closure captures a copy of each plain variable, so its changes aren't seen outside it. A cell holds one value that every copy of the cell shares, so a write through one is seen through all.
A cell created with a built-in value, such as an integer or a string, only accepts values of that type.
> functions
> types
> examples
use std::cell;
use std::io;
fn main() {
let counter = cell::new(0);
let inc = || {
counter.set(counter.get() + 1);
};
inc();
inc();
io::println("count: {}", counter.get());
}