pub struct ArcShiftCell<T: 'static + ?Sized> { /* private fields */ }Expand description
ArcShiftCell is like an ArcShift, except that it can be reloaded without requiring ‘mut’-access. However, it is not ‘Sync’.
It does not implement ‘Deref’, but does implement a ArcShiftCell::borrow-method which returns,
a non-threadsafe ArcShiftCellHandle<T>. This handle implements Deref, giving access
to the pointed to &T. This handle should not be leaked,
but if it is leaked, the effect is that whatever value the ArcShiftCell-instance
pointed to at that time, will forever leak also.
Implementations§
Source§impl<T: 'static> ArcShiftCell<T>
impl<T: 'static> ArcShiftCell<T>
Sourcepub fn new(value: T) -> ArcShiftCell<T>
pub fn new(value: T) -> ArcShiftCell<T>
Create a new ArcShiftCell with the given value.
Source§impl<T: 'static + ?Sized> ArcShiftCell<T>
impl<T: 'static + ?Sized> ArcShiftCell<T>
Sourcepub fn from_arcshift(input: ArcShift<T>) -> ArcShiftCell<T>
pub fn from_arcshift(input: ArcShift<T>) -> ArcShiftCell<T>
Creates an ArcShiftCell from an ArcShift-instance. The payload is not cloned, the two pointers keep pointing to the same object.
Sourcepub fn borrow(&self) -> ArcShiftCellHandle<'_, T>
pub fn borrow(&self) -> ArcShiftCellHandle<'_, T>
Get a handle to the pointed-to T.
Make sure not to leak this handle: See further documentation on
ArcShiftCellHandle. Leaking the handle will leak resources, but
not cause undefined behaviour.
Sourcepub fn get<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn get<R>(&self, f: impl FnOnce(&T) -> R) -> R
Get the value pointed to.
This method is very fast, basically the speed of a regular reference, unless the value has been modified by calling one of the update-methods.
This method will do a reload (drop older values which are no longer needed).
This method is reentrant - you are allowed to call it from within the closure ‘f’. However, only the outermost invocation will cause a reload.
Sourcepub fn assign(&self, other: &ArcShift<T>) -> Result<(), RecursionDetected>
pub fn assign(&self, other: &ArcShift<T>) -> Result<(), RecursionDetected>
Assign the given ArcShift to this instance. This does not copy the value T, it replaces the ArcShift instance of Self with a clone of ‘other’. It does not clone T, only the ArcShift holding it.
This returns Err if recursion is detected, and has no effect in this case. Recursion occurs if ‘assign’ is called from within the closure supplied to the ‘ArcShiftCell::get’-method.
Sourcepub fn reload(&self)
pub fn reload(&self)
Reload this ArcShiftCell-instance. This allows heap blocks kept alive by this instance of ArcShiftCell to be dropped. Note, this method only works when not called from within a closure supplied to the ‘get’ method. If such recursion occurs, this method does nothing.
Sourcepub fn make_arcshift(&self) -> ArcShift<T>
pub fn make_arcshift(&self) -> ArcShift<T>
Create an ArcShift-instance pointing to the same value as this cell.
Trait Implementations§
Source§impl<T: 'static + ?Sized> Clone for ArcShiftCell<T>
impl<T: 'static + ?Sized> Clone for ArcShiftCell<T>
Source§impl<T> Debug for ArcShiftCell<T>
impl<T> Debug for ArcShiftCell<T>
impl<T> Send for ArcShiftCell<T>
ArcShiftCell cannot be Sync, but there’s nothing stopping it from being Send.
Note that ArcShiftCell cannot be Sync, because then multiple threads could call ‘get’ simultaneously, corrupting the (non-atomic) refcount.