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>
impl<T: 'static> ArcShiftLight<T>
sourcepub fn new(payload: T) -> ArcShiftLight<T>
pub fn new(payload: T) -> ArcShiftLight<T>
Create a new ArcShiftLight-instance, containing the given value.
sourcepub fn reload(&mut self)
pub fn reload(&mut self)
Reload this ArcShiftLight-instance. This allows dropping heap blocks kept alive by this instance of ArcShiftLight to be dropped.
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.
sourcepub fn update(&mut self, new_payload: T)
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.
sourcepub fn update_box(&mut self, new_payload: Box<T>)
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.
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.
Trait Implementations§
source§impl<T: 'static> Clone for ArcShiftLight<T>
impl<T: 'static> Clone for ArcShiftLight<T>
source§impl<T: 'static + ?Sized> Drop for ArcShiftLight<T>
impl<T: 'static + ?Sized> Drop for ArcShiftLight<T>
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
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)