Struct basedrop::Shared [−][src]
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
impl<T: Send + 'static> Shared<T>
[src]
pub fn new(handle: &Handle, data: T) -> Shared<T>
[src]
Constructs a new Shared<T>
.
Examples
use basedrop::{Collector, Shared}; let collector = Collector::new(); let three = Shared::new(&collector.handle(), 3);
impl<T> Shared<T>
[src]
pub fn get_mut(this: &mut Self) -> Option<&mut T>
[src]
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
impl<T> Clone for Shared<T>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T> Deref for Shared<T>
[src]
impl<T> Drop for Shared<T>
[src]
impl<T: Send + Sync> Send for Shared<T>
[src]
impl<T: Send + Sync> Sync for Shared<T>
[src]
Auto Trait Implementations
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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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>,