pub struct SharedCell<T> { /* private fields */ }
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§
Sourcepub fn new(value: Shared<T>) -> SharedCell<T>
pub fn new(value: Shared<T>) -> SharedCell<T>
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);
Sourcepub fn set(&self, value: Shared<T>)
pub fn set(&self, value: Shared<T>)
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);
Sourcepub fn into_inner(self) -> Shared<T>
pub fn into_inner(self) -> Shared<T>
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§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more