pub struct VWeak<T: ?Sized, A: MemPool> { /* private fields */ }
Expand description

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 upgraded. 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::demote.

Implementations

Attempts to promote 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 corundum::default::*;
use std::mem::drop;
 
type P = Allocator;
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))))
    }
}

let vweak_obj = obj.0.borrow().as_ref().unwrap().demote();
 
P::transaction(|j| {
    let strong_obj = vweak_obj.promote(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.promote(j).is_none());
}).unwrap();

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.