Struct basedrop::SharedCell[][src]

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

A thread-safe shared mutable memory location that holds a Shared<T>.

SharedCell is designed to be low-overhead for readers at the expense of somewhat higher overhead for writers.

Implementations

Constructs a new SharedCell containing value.

Examples

use basedrop::{Collector, Shared, SharedCell};

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

Gets a copy of the contained Shared<T>, incrementing its reference count in the process.

Examples

use basedrop::{Collector, Shared, SharedCell};

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

let y = cell.get();

Replaces the contained Shared<T>, decrementing its reference count in the process.

Examples

use basedrop::{Collector, Shared, SharedCell};

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

let y = Shared::new(&collector.handle(), 4);
cell.set(y);

Replaces the contained Shared<T> and returns it.

Examples

use basedrop::{Collector, Shared, SharedCell};

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

let y = Shared::new(&collector.handle(), 4);
let x = cell.replace(y);

Consumes the SharedCell and returns the contained Shared<T>. This is safe because we are guaranteed to be the only holder of the SharedCell.

Examples

use basedrop::{Collector, Shared, SharedCell};

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

let x = cell.into_inner();

Trait Implementations

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 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.