Struct rccell::WeakCell[][src]

pub struct WeakCell<T>(_);
Expand description

Version of RefCell that holds a non-owning reference to the managed allocation.

Implementations

Constructs a new WeakCell<T>, without allocating any memory. Calling WeakCell::upgrade on the return value always gives None.

Examples

use rccell::WeakCell;

let empty: WeakCell<i32> = WeakCell::new();
assert!(empty.upgrade().is_none());

Similar to Weak::upgrade. Attempts to upgrade the WeakCell pointer to an RcCell. Returns None if the inner value has been dropped.

Examples

use rccell::RcCell;

let five = RcCell::new(5);

let weak_five = five.downgrade();
let strong_five = weak_five.upgrade();
assert!(strong_five.is_some());

drop(strong_five);
drop(five);
assert!(weak_five.upgrade().is_none());

Gets the number of strong (RcCell) pointers pointing to this allocation. If self was created using WeakCell::new, this will return 0.

Gets the number of WeakCell pointers pointing to this allocation. If no strong pointers remain, this will return 0.

Returns true if the two Weaks point to the same allocation, or if both don’t point to any allocation.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a 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

Performs the conversion.

Performs the conversion.

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)

recently added

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.