pub struct ArcShiftWeak<T: ?Sized> { /* private fields */ }Expand description
ArcShiftWeak is a way to keep a pointer to an object without preventing said object from being deallocated. This can be useful when creating cyclic data structure, to avoid memory leaks.
let original_instance = ArcShift::new("test");
let light_instance = ArcShift::downgrade(&original_instance);
let mut instance = light_instance.upgrade().unwrap();
println!("Value: {:?}", instance.get());WARNING! Because of implementation reasons, each instance of ArcShiftWeak will claim
a memory equal to size_of::<T> (plus 5 words), even if the value inside it has freed,
and even if all other instances of ArcShift/ArcShiftWeak have been dropped.
If this limitation is unacceptable, consider using ArcShiftWeak<Box<T>> as your datatype,
or possibly using a different crate.
Implementations§
Source§impl<T: ?Sized> ArcShiftWeak<T>
impl<T: ?Sized> ArcShiftWeak<T>
Trait Implementations§
Source§impl<T: ?Sized> Clone for ArcShiftWeak<T>
impl<T: ?Sized> Clone for ArcShiftWeak<T>
Source§impl<T> Debug for ArcShiftWeak<T>
impl<T> Debug for ArcShiftWeak<T>
Source§impl<T: ?Sized> Drop for ArcShiftWeak<T>
impl<T: ?Sized> Drop for ArcShiftWeak<T>
impl<T: Sync + Send + ?Sized> Send for ArcShiftWeak<T>
SAFETY:
If T is Sync and Send, ArcShiftWeak<T> can also be Send
impl<T: Sync + Send + ?Sized> Sync for ArcShiftWeak<T>
SAFETY:
If T is Sync and Send, ArcShiftWeak<T> can also be Sync
Auto Trait Implementations§
impl<T> Freeze for ArcShiftWeak<T>where
T: ?Sized,
impl<T> RefUnwindSafe for ArcShiftWeak<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Unpin for ArcShiftWeak<T>where
T: ?Sized,
impl<T> UnwindSafe for ArcShiftWeak<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
Mutably borrows from an owned value. Read more