pub struct SharedBoxRef<T: ?Sized> { /* private fields */ }Expand description
A Reference to SharedBox that can be sent to other threads.
Dropping a SharedBoxRef leaks the heap memory it points to.
When panic-on-drop feature is enabled, dropping it will panic:
ⓘ
let mut b = manual_share::SharedBox::new(1);
b.borrow();
// forget SharedBox to make sure the panic is not caused by dropping it first.
std::mem::forget(b);
// panic here due to dropping SharedBoxRefUse SharedBox::try_return to consume it without causing panic.
let mut b = manual_share::SharedBox::new(1);
let r = b.borrow();
b.try_return(r).unwrap();Implementations§
Sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Example usage:
let mut b = manual_share::SharedBox::new(42);
let r = b.borrow();
let value = *r.get();
assert_eq!(value, 42);
b.try_return(r).unwrap();The reference got from this method has the same lifetime of the SharedBoxRef,
which means it will be invalidated after SharedBoxRef is given back to SharedBox:
ⓘ
let mut b = manual_share::SharedBox::new(42);
let br = b.borrow();
let r = br.get();
b.try_return(br).unwrap();
// r is no longer valid here.
println!("{}", r);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