0.1.0 |
|
---|
#43 in #refcell
9KB
162 lines
BoCell
This is a simple Rust crate which implements a borrowing Cell variant.
In some cases where the internal mutability and reference properties of a RefCell is required it is
advantageous to coerce that Cell from a reference on a temporary basis rather than storing the data as
contained in a RefCell and constantly contending with the runtime borrow-checking RefCells employ.
BoCell is a RefCell which borrows its contents from a &mut
while in scope. This allows for
non-overlapping mutable borrows to be taken simultaneously from behind a single &mut
.
Features
This is a one track crate. BoCell
can be created from a &mut
and may be mutably borrowed from
once at a time as a RefMut
.
RefMut
implement both Deref
traits and so can be used like any other reference in terms of
method calls. RefMut
can also be manipulated by it's associated functions RefMut::map()
subreferences, RefMut::split_tuple()
, and RefMut::split_triple()
split the reference into 2 and 3
parts. Be mindful when splitting RefMut
s, having two overlapping mutable borrows active at once is
undefined behaviour.