[−][src]Struct crndm::sync::Weak
Weak
is a version of Parc
that holds a non-owning reference to the
managed allocation. The allocation is accessed by calling upgrade
on the
Weak
pointer, which returns an Option
<
Parc
<T>>
.
Since a Weak
reference does not count towards ownership, it will not
prevent the value stored in the allocation from being dropped, and Weak
itself makes no guarantees about the value still being present. Thus it may
return None
when upgrade
d. Note however that a Weak
reference
does prevent the allocation itself (the backing store) from being
deallocated.
A Weak
pointer is useful for keeping a temporary reference to the
allocation managed by Parc
without preventing its inner value from being
dropped. It is also used to prevent circular references between Parc
pointers, since mutual owning references would never allow either Parc
to be dropped. For example, a tree could have strong Parc
pointers from
parent nodes to children, and Weak
pointers from children back to their
parents.
The typical way to obtain a Weak
pointer is to call Parc::downgrade
.
Implementations
impl<T: PSafe, A: MemPool> Weak<T, A>
[src]
pub fn as_raw(&self) -> *const T
[src]
pub fn into_raw(self) -> *const T
[src]
pub unsafe fn from_raw(ptr: *const T) -> Self
[src]
impl<T: PSafe + ?Sized, A: MemPool> Weak<T, A>
[src]
pub fn new() -> Weak<T, A>
[src]
Creates a new dangling weak pointer
pub fn upgrade(&self, _journal: &Journal<A>) -> Option<Parc<T, A>>
[src]
Attempts to upgrade the Weak
pointer to an Parc
, delaying
dropping of the inner value if successful.
Returns None
if the inner value has since been dropped.
Examples
use crndm::alloc::*; use crndm::sync::Parc; Heap::transaction(|j| { let five = Parc::new(5, j); let weak_five = Parc::downgrade(&five, j); let strong_five = weak_five.upgrade(j); assert!(strong_five.is_some()); // Destroy all strong pointers. drop(strong_five); drop(five); assert!(weak_five.upgrade(j).is_none()); }).unwrap()
pub fn strong_count(&self) -> usize
[src]
Gets the number of strong (Parc
) pointers pointing to this allocation.
If self
was created using Weak::new
, this will return 0.
pub fn weak_count(&self) -> usize
[src]
Gets an approximation of the number of Weak
pointers pointing to this
allocation.
If self
was created using Weak::new
, or if there are no remaining
strong pointers, this will return 0.
Accuracy
Due to implementation details, the returned value can be off by 1 in
either direction when other threads are manipulating any Parc
s or
Weak
s pointing to the same allocation.
pub fn ptr_eq(&self, other: &Self) -> bool
[src]
Returns true
if the two Weak
s point to the same allocation (similar to
std::ptr::eq
), or if both don't point to any allocation
(because they were created with Weak::new()
).
Notes
Since this compares pointers it means that Weak::new()
will equal each
other, even though they don't point to any allocation.
Trait Implementations
impl<T: PSafe + ?Sized + Debug, A: MemPool> Debug for Weak<T, A>
[src]
impl<T: PSafe + ?Sized, A: MemPool> Default for Weak<T, A>
[src]
impl<T: PSafe + ?Sized, A: MemPool> Drop for Weak<T, A>
[src]
impl<T: PSafe + ?Sized, A: MemPool> PClone<A> for Weak<T, A>
[src]
pub fn pclone(&self, _journal: &Journal<A>) -> Weak<T, A>
[src]
pub fn pclone_from(&mut self, source: &Self, journal: &Journal<A>)
[src]
impl<T: ?Sized, A: MemPool> !Send for Weak<T, A>
[src]
impl<T: ?Sized, A: MemPool> !Sync for Weak<T, A>
[src]
impl<T: ?Sized, A: MemPool> !TxOutSafe for Weak<T, A>
[src]
impl<T: ?Sized, A: MemPool> !VSafe for Weak<T, A>
[src]
Auto Trait Implementations
impl<T: ?Sized, A> LooseTxInUnsafe for Weak<T, A> where
A: LooseTxInUnsafe,
T: LooseTxInUnsafe,
[src]
A: LooseTxInUnsafe,
T: LooseTxInUnsafe,
impl<T: ?Sized, A> PSafe for Weak<T, A>
[src]
impl<T: ?Sized, A> RefUnwindSafe for Weak<T, A> where
A: RefUnwindSafe,
T: RefUnwindSafe,
[src]
A: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, A> !TxInSafe for Weak<T, A>
[src]
impl<T: ?Sized, A> Unpin for Weak<T, A> where
A: Unpin,
T: Unpin,
[src]
A: Unpin,
T: Unpin,
impl<T: ?Sized, A> UnwindSafe for Weak<T, A> where
A: UnwindSafe,
T: UnwindSafe,
[src]
A: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,