Lineage
A small rust crate that provides a type of cell that can replace its contained value while the previous value is still immutably borrowed:
Notice how a new value can be inserted into the cell with Lineage::set using only &self.
This means the Lineage may still be borrowed by previous calls to Lineage::get but you can replace the contained value anyways.
Internally the replaced value is added to a linked list which is not cleared until you call Lineage::clear or drop the Lineage.
let lineage: = new;
let s1 = lineage.get;
lineage.set;
let s2 = lineage.get;
assert_eq!;
assert_eq!;
Safety
As is expected for this kind of utility crate, the implementation makes use of unsafe.
We have a number of tests to look for undefined behavior which can all be run natively or with miri.
miri is a fantastic tool to execute rust applications in a virtual runtime that is sensitive to various kinds of undefined behavior.
# run tests normally
cargo test
# install miri
rustup toolchain install nightly
rustup +nightly component add miri
# run tests in miri
cargo clean
cargo +nightly miri test