Struct basedrop::SharedCell [−][src]
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
impl<T: Send + 'static> SharedCell<T>
[src]
pub fn new(value: Shared<T>) -> SharedCell<T>
[src]
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);
impl<T> SharedCell<T>
[src]
pub fn get(&self) -> Shared<T>
[src]
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();
pub fn set(&self, value: Shared<T>)
[src]
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);
pub fn replace(&self, value: Shared<T>) -> Shared<T>
[src]
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);
pub fn into_inner(self) -> Shared<T>
[src]
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
impl<T> Drop for SharedCell<T>
[src]
impl<T: Send + Sync> Send for SharedCell<T>
[src]
impl<T: Send + Sync> Sync for SharedCell<T>
[src]
Auto Trait Implementations
impl<T> Unpin for SharedCell<T> where
T: Unpin,
T: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,