pub struct Shared<T> { /* private fields */ }
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§
Sourcepub fn get_mut(this: &mut Self) -> Option<&mut T>
pub fn get_mut(this: &mut Self) -> Option<&mut T>
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§
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