cell-family

Cells inspired by qcell::TCell / qcell::TLCell, with additional features.

Overview

cell-family provides the define! macro, which defines a new Family. For each family, a corresponding Cell and CellOwner can be created. Only a single CellOwner per family can exist at once, but multiple cells can exist at the same time.

For instance, you may define a family FooFamily as below:

rust cell_family::define!(type FooFamily: FooCellOwner for FooCell<T>);

This defines FooFamily (which implements Family) as well as FooCellOwner and FooCell, aliases for CellOwner<FooFamily> and Cell<FooFamily> respectively.

One FooCellOwner can exist per thread, and thus FooCellOwner is not Send, since sending a FooCellOwner to another thread may allow two FooCellOwners to co-exist in a single thread. To allow a single FooCellOwner per program (and thus make FooCellOwner Send), prefix define! with static:

rust cell_family::define!(static type FooFamily: FooCellOwner for FooCell<T>);

For both thread-local and thread-safe families, the API is the same:

```rust let mut owner = FooCellOwner::new(); let a = FooCell::new(1); let b = FooCell::new("bar");

asserteq!(*a.get(&owner), 1); asserteq!(*b.get(&owner), "bar");

*a.getmut(&mut owner) += 1; *b.getmut(&mut owner) = "baz";

asserteq!(*a.get(&owner), 2); asserteq!(*b.get(&owner), "baz"); ```

Benefits over qcell::TCell / qcell::TLCell