[−][src]Struct crndm::sync::VWeak
VWeak
is a version of Parc
that holds a non-owning thread-safe
reference to the managed allocation in the volatile heap. The allocation is
accessed by calling upgrade
on the VWeak
pointer, which returns an
Option
<
Parc
<T>>
.
Since a VWeak
reference does not count towards ownership, it will not
prevent the value stored in the allocation from being dropped, and VWeak
itself makes no guarantees about the value still being present. Thus it may
return None
when upgrade
d. Note however that a VWeak
reference,
unlike Weak
, does NOT prevent the allocation itself (the backing
store) from being deallocated.
A VWeak
pointer is useful for keeping a temporary thread-safe reference to
the persistent allocation managed by Parc
without preventing its inner
value from being dropped.
The typical way to obtain a VWeak
pointer is to call Parc::volatile
.
Implementations
impl<T: PSafe + ?Sized, A: MemPool> VWeak<T, A>
[src]
pub fn upgrade(&self, _journal: &Journal<A>) -> Option<Parc<T, A>>
[src]
Attempts to upgrade the VWeak
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::default::*; use std::mem::drop; type P = BuddyAlloc; let obj = P::open::<Root>("foo.pool", O_CF).unwrap(); struct Root(PRefCell<Option<Parc<i32>>>); impl RootObj<P> for Root { fn init(j: &Journal) -> Self { Root(PRefCell::new(Some(Parc::new(10, j)),j)) } } let vweak_obj = obj.0.borrow().as_ref().unwrap().volatile(); P::transaction(|j| { let strong_obj = vweak_obj.upgrade(j); assert!(strong_obj.is_some()); // Destroy all strong pointers. drop(strong_obj); *obj.0.borrow_mut(j) = None; // RootCell does not drop, so make it None assert!(vweak_obj.upgrade(j).is_none()); }).unwrap();
Trait Implementations
impl<T: PSafe + ?Sized, A: MemPool> Clone for VWeak<T, A>
[src]
pub fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: ?Sized, A: MemPool> Drop for VWeak<T, A>
[src]
impl<T: ?Sized, A: MemPool> PSafe for VWeak<T, A>
[src]
impl<T: ?Sized, A: MemPool> RefUnwindSafe for VWeak<T, A>
[src]
impl<T: ?Sized, A: MemPool> Send for VWeak<T, A>
[src]
impl<T: ?Sized, A: MemPool> Sync for VWeak<T, A>
[src]
impl<T: ?Sized, A: MemPool> TxInSafe for VWeak<T, A>
[src]
impl<T: ?Sized, A: MemPool> TxOutSafe for VWeak<T, A>
[src]
impl<T: ?Sized, A: MemPool> UnwindSafe for VWeak<T, A>
[src]
Auto Trait Implementations
impl<T: ?Sized, A> LooseTxInUnsafe for VWeak<T, A> where
A: LooseTxInUnsafe,
T: LooseTxInUnsafe,
[src]
A: LooseTxInUnsafe,
T: LooseTxInUnsafe,
impl<T: ?Sized, A> Unpin for VWeak<T, A>
[src]
impl<T, A> !VSafe for VWeak<T, A>
[src]
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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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>,