Struct basedrop::Shared[][src]

pub struct Shared<T> { /* fields omitted */ }
Expand description

A reference-counted smart pointer with deferred collection, analogous to Arc.

When a Shared<T>’s reference count goes to zero, its contents are added to the drop queue of the Collector whose Handle it was originally allocated with. As the collector may be on another thread, contents are required to be Send + 'static.

Implementations

Constructs a new Shared<T>.

Examples

use basedrop::{Collector, Shared};

let collector = Collector::new();
let three = Shared::new(&collector.handle(), 3);

Returns a mutable reference to the contained value if there are no other extant Shared pointers to the same allocation; otherwise returns None.

Examples

use basedrop::{Collector, Shared};

let collector = Collector::new();
let mut x = Shared::new(&collector.handle(), 3);

*Shared::get_mut(&mut x).unwrap() = 4;
assert_eq!(*x, 4);

let _y = Shared::clone(&x);
assert!(Shared::get_mut(&mut x).is_none());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

The resulting type after dereferencing.

Dereferences the value.

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

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.