pub struct Write<T: ?Sized>(/* private fields */);Expand description
A marker type which indicates that any owning Gc has been marked as having been modified.
Implementations§
Source§impl<T: ?Sized> Write<T>
impl<T: ?Sized> Write<T>
Sourcepub unsafe fn new_unchecked(value: &T) -> &Write<T>
pub unsafe fn new_unchecked(value: &T) -> &Write<T>
pub fn new_static(value: &T) -> &Write<T>where
T: 'static,
pub fn into_inner(&self) -> &T
pub fn unlock(&self) -> &T::Unlockedwhere
T: Unlock,
Sourcepub fn project<U: ?Sized>(
&self,
f: impl for<'a> FnOnce(&'a T) -> &'a U,
) -> &Write<U>
pub fn project<U: ?Sized>( &self, f: impl for<'a> FnOnce(&'a T) -> &'a U, ) -> &Write<U>
Projects a write permission into a write permision of the of the values contained by
self.
§Panics
When the closure returns a reference to a value not contained within the bounds of self.
Sourcepub fn try_project<U: ?Sized>(
&self,
f: impl for<'a> FnOnce(&'a T) -> &'a U,
) -> Result<&Write<U>, WriteProjectError>
pub fn try_project<U: ?Sized>( &self, f: impl for<'a> FnOnce(&'a T) -> &'a U, ) -> Result<&Write<U>, WriteProjectError>
Projects a write permission into a write permision of the of the values contained by
self, returning an error if the closure returns a reference to a value not contained
within the bounds of self.
Sourcepub unsafe fn project_unchecked<U: ?Sized>(
&self,
f: impl for<'a> FnOnce(&'a T) -> &'a U,
) -> &Write<U>
pub unsafe fn project_unchecked<U: ?Sized>( &self, f: impl for<'a> FnOnce(&'a T) -> &'a U, ) -> &Write<U>
Projects a write permission into a write permission of one of the containing objects fields.
§Safety
The given closure must return a reference to a value which is owned by self. The closure
must not dereference a Gc, or in any way project into a value which is owned
by another garbage collected pointer, and which could itself contain a garbage collected
pointer.
§Examples
#[derive(Debug)]
struct LinkedList<'b, T> {
data: T,
next: LockedCell<Option<Gc<'b, Self>>>,
}
let head = Gc::new(LinkedList::<'_, u32> {
data: 0,
next: LockedCell::new(Some(Gc::new(LinkedList {
data: 1,
next: LockedCell::new(None)
}, mt)))
}, mt);
unsafe {
head.write().project_unchecked(|x| &x.data);
head.write().project_unchecked(|x| &x.next);
}