stack-cell-ref 0.3.0

Share a reference in thread inner.
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented6 out of 6 items with examples
  • Size
  • Source code size: 18.43 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 393 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • 823984418/stack-cell-ref
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 823984418

Stack Cell Ref

Share a reference in thread inner.

Examples

use std::cell::Cell;
use stack_cell_ref::CellOptionRef;
struct Foo {
    x: Cell<i32>,
}

thread_local! {
    static S: CellOptionRef<Foo> = CellOptionRef::new();
}

fn set_foo(x: i32) {
    S.with(|c| {
        c.read(|f| {
            f.unwrap().x.set(x);
        });
    });
}

let foo = Foo { x: Cell::new(0) };

S.with(|c| {
    c.with(Some(&foo), || {
        set_foo(1);
    });
    assert_eq!(c.get_ptr(), None);
});
assert_eq!(foo.x.get(), 1);