Struct ArcShiftCell

Source
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. All the linked-list nodes from that entry and onward will also leak. So make sure to not leak the handle!

Implementations§

Source§

impl<T: 'static> ArcShiftCell<T>

Source

pub fn new(value: T) -> ArcShiftCell<T>

Create a new ArcShiftCell with the given value.

Source§

impl<T: 'static + ?Sized> ArcShiftCell<T>

Source

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.

Source

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.

Source

pub fn get(&self, f: impl FnOnce(&T))

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.

Source

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.

Source

pub fn reload(&self)

Reload this ArcShiftCell-instance. This allows dropping 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.

Source

pub fn make_arcshift(&self) -> ArcShift<T>

Create an ArcShift-instance pointing to the same data

Trait Implementations§

Source§

impl<T: 'static + ?Sized> Clone for ArcShiftCell<T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for ArcShiftCell<T>
where T: Debug + ?Sized + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Send for ArcShiftCell<T>
where T: Send + Sync + 'static,

ArcShiftCell cannot be Sync, but there’s nothing stopping it from being Send. SAFETY: As long as the contents of the cell are not !Send, it is safe to send the cell. The object must be uniquely owned to be sent, and this is only possible if we’re not in a recursive call to ‘get’. And in this case, the properties of ArcShiftCell are the same as ArcShift, and ArcShift is Send (if T is Send + Sync).

Note that ArcShiftCell cannot be Sync, because then multiple threads could call ‘get’ simultaneously, corrupting the (non-atomic) refcount.

Auto Trait Implementations§

§

impl<T> !Freeze for ArcShiftCell<T>

§

impl<T> !RefUnwindSafe for ArcShiftCell<T>

§

impl<T> !Sync for ArcShiftCell<T>

§

impl<T> Unpin for ArcShiftCell<T>
where T: ?Sized,

§

impl<T> UnwindSafe for ArcShiftCell<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.