Struct basedrop::Shared [−][src]
pub struct Shared<T> { /* fields omitted */ }
Expand description
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
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
Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more