[−][src]Struct qcell::LCellOwner
Borrowing-owner of zero or more LCell
instances.
Use LCellOwner::scope(|owner| ...)
to create an instance of this
type.
The key piece of Rust syntax that enables this is for<'id>
.
This allows creating an invariant lifetime within a closure, which
is different to any other Rust lifetime thanks to the techniques
explained in various places: section 6.3 of this thesis from
Gankro,
this Reddit
post,
and this Rust playground
example.
Also see this Reddit
comment
and its linked playground code.
LCellOwner
uses a closure to contain the invariant lifetime.
However it's also worth noting the alternative approach used in
crate generativity
that
uses a macro instead.
Some history: GhostCell
by
pythonesque predates the
creation of LCell
, and inspired it. Discussion of GhostCell
on Reddit showed that a lifetime-based approach to cells was
feasible, but unfortunately the ghost_cell.rs
source didn't seem
to be available under a community-friendly licence. So I went
back to first principles and created LCell
from TCell
code,
combined with invariant lifetime code derived from the various
community sources that predate GhostCell
. Later Send
and
Sync
support for LCell
was contributed independently.
See also crate documentation.
Implementations
impl<'id> LCellOwner<'id>
[src]
pub fn scope<F>(f: F) where
F: for<'scope_id> FnOnce(LCellOwner<'scope_id>),
[src]
F: for<'scope_id> FnOnce(LCellOwner<'scope_id>),
Create a new LCellOwner
, with a new lifetime, that exists
only within the scope of the execution of the given closure
call. If two scope calls are nested, then the two owners get
different lifetimes.
pub fn cell<T>(&self, value: T) -> LCell<'id, T>
[src]
Create a new cell owned by this owner instance. See also
LCell::new
.
pub fn ro<'a, T>(&'a self, lc: &'a LCell<'id, T>) -> &'a T
[src]
Borrow contents of a LCell
immutably (read-only). Many
LCell
instances can be borrowed immutably at the same time
from the same owner.
pub fn rw<'a, T>(&'a mut self, lc: &'a LCell<'id, T>) -> &'a mut T
[src]
Borrow contents of a LCell
mutably (read-write). Only one
LCell
at a time can be borrowed from the owner using this
call. The returned reference must go out of scope before
another can be borrowed.
pub fn rw2<'a, T, U>(
&'a mut self,
lc1: &'a LCell<'id, T>,
lc2: &'a LCell<'id, U>
) -> (&'a mut T, &'a mut U)
[src]
&'a mut self,
lc1: &'a LCell<'id, T>,
lc2: &'a LCell<'id, U>
) -> (&'a mut T, &'a mut U)
Borrow contents of two LCell
instances mutably. Panics if
the two LCell
instances point to the same memory.
pub fn rw3<'a, T, U, V>(
&'a mut self,
lc1: &'a LCell<'id, T>,
lc2: &'a LCell<'id, U>,
lc3: &'a LCell<'id, V>
) -> (&'a mut T, &'a mut U, &'a mut V)
[src]
&'a mut self,
lc1: &'a LCell<'id, T>,
lc2: &'a LCell<'id, U>,
lc3: &'a LCell<'id, V>
) -> (&'a mut T, &'a mut U, &'a mut V)
Borrow contents of three LCell
instances mutably. Panics if
any pair of LCell
instances point to the same memory.
Trait Implementations
impl<'id> Sync for LCellOwner<'id>
[src]
Auto Trait Implementations
impl<'id> !RefUnwindSafe for LCellOwner<'id>
impl<'id> Send for LCellOwner<'id>
impl<'id> Unpin for LCellOwner<'id>
impl<'id> !UnwindSafe for LCellOwner<'id>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,