xur_

> 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

# new(value: T) -> Cell<T>

Create a new cell containing value.

> types

┌ type Cell
# cell.get() -> T

Returns the current value.

# cell.set(value: T)

Replaces the value. A value of another type than the cell was created with is a runtime error.

> 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());
}