Struct arcshift::ArcShiftLight

source ·
pub struct ArcShiftLight<T: 'static + ?Sized> { /* private fields */ }
Expand description

ArcShiftLight is like ArcShift, except it does not provide overhead-free access. However, it has the advantage of not preventing old versions of the payload type from being freed.

let light_instance = ArcShiftLight::new("test");
let instance = light_instance.upgrade();
println!("Value: {:?}", *instance);

WARNING! Because of implementation reasons, each instance of ArcShiftLight will claim a memory equal to size_of::<T> (plus a bit), even if the value inside it has been moved out, and even if all other instances of ArcShift/ArcShiftLight have been dropped. If this limitation is unacceptable, consider using ArcShiftLight<Box<T>> as your datatype, or possibly using a different crate.

Implementations§

source§

impl<T: 'static> ArcShiftLight<T>

source

pub fn new(payload: T) -> ArcShiftLight<T>

Create a new ArcShiftLight-instance, containing the given value.

source

pub fn reload(&mut self)

Reload this ArcShiftLight-instance. This allows dropping heap blocks kept alive by this instance of ArcShiftLight to be dropped.

source

pub fn update_shared(&self, new_payload: T)

Update the contents of this ArcShift, and all other instances cloned from this instance. The next time such an instance of ArcShift is dereferenced, this new value will be returned.

This method never blocks, it will return quickly.

WARNING! Calling this function does not cause the old value to be dropped before the new value is stored. The old instance of T is dropped when the last ArcShift instance is dropped or reloaded.

source

pub fn update(&mut self, new_payload: T)

Update the contents of this ArcShiftLight, and all other instances cloned from this instance. The next time such an instance of ArcShift is dereferenced, this new value will be returned.

This method never blocks, it will return quickly.

WARNING! Calling this function does not cause the old value to be dropped before the new value is stored. The old instance of T is dropped when the last ArcShift instance reloads to the new value. This reload happens only when the last instance is dropped or reloaded.

Note, this method, in contrast to ‘upgrade_shared’, actually does reload the ‘self’ ArcShiftLight-instance. This has the effect that if ‘self’ is the last remaining instance, the old value that is being replaced will be dropped before this function returns.

source

pub fn update_box(&mut self, new_payload: Box<T>)

Update the contents of this ArcShiftLight, and all other instances cloned from this instance. The next time such an instance of ArcShift is dereferenced, this new value will be returned.

This method never blocks, it will return quickly.

This function is useful for types T which are too large to fit on the stack. The value T will be moved directly to the internal heap-structure, without being even temporarily stored on the stack, even in debug builds.

WARNING! Calling this function does not cause the old value to be dropped before the new value is stored. The old instance of T is dropped when the last ArcShift instance reloads to the new value. This reload happens only when the last instance is dropped or reloaded.

Note, this method, in contrast to ‘upgrade_shared’, actually does reload the ‘self’ ArcShiftLight-instance. This has the effect that if ‘self’ is the last remaining instance, the old value that is being replaced will be dropped before this function returns.

source

pub fn update_shared_box(&self, new_payload: Box<T>)

Update the contents of this ArcShift, and all other instances cloned from this instance. The next time such an instance of ArcShift is dereferenced, this new value will be returned.

This method never blocks, it will return quickly.

This function is useful for types T which are too large to fit on the stack. The value T will be moved directly to the internal heap-structure, without being even temporarily stored on the stack, even in debug builds.

WARNING! Calling this function does not cause the old value to be dropped before the new value is stored. The old instance of T is dropped when the last ArcShift instance is dropped or reloaded.

source

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

Create an ArcShift instance from this ArcShiftLight.

Trait Implementations§

source§

impl<T: 'static> Clone for ArcShiftLight<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: 'static + ?Sized> Drop for ArcShiftLight<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

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

SAFETY: ArcShiftLight can be Send as long as T is Send. ArcShiftLight’s mechanisms are compatible with both Send and Sync

source§

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

SAFETY: ArcShiftLight can be Sync as long as T is Sync. ArcShiftLight’s mechanisms are compatible with both Send and Sync

Auto Trait Implementations§

§

impl<T> Freeze for ArcShiftLight<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for ArcShiftLight<T>
where T: RefUnwindSafe + ?Sized,

§

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

§

impl<T> UnwindSafe for ArcShiftLight<T>
where T: RefUnwindSafe + ?Sized,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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>,

§

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>,

§

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.