Struct basedrop::Shared[][src]

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

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]

impl<T> Deref for Shared<T>[src]

type Target = T

The resulting type after dereferencing.

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

impl<T> Unpin for Shared<T> where
    T: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.