pub struct ThreadGuard<T: ?Sized> { /* private fields */ }
Expand description
Stores a value in a threadafe container that only lets you access it from its owning thread
If the ThreadGuard is dropped from the wrong thread, the underlying value will be leaked.
Implementations§
Source§impl<T> ThreadGuard<T>
impl<T> ThreadGuard<T>
Sourcepub fn new(val: T) -> ThreadGuard<T>
pub fn new(val: T) -> ThreadGuard<T>
Create a new ThreadGuard wrapper
Source§impl<T: ?Sized> ThreadGuard<T>
impl<T: ?Sized> ThreadGuard<T>
Sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Mutably access the underlying value
Panics if done on the wrong thread
Sourcepub fn try_get(&self) -> Option<&T>
pub fn try_get(&self) -> Option<&T>
Try to access the underlying value
Returns None
if done on the wrong thread
Sourcepub fn try_get_mut(&mut self) -> Option<&mut T>
pub fn try_get_mut(&mut self) -> Option<&mut T>
Try to mutably access the underlying value
Returns None
if done on the wrong thread
Trait Implementations§
Source§impl<T: ?Sized> Drop for ThreadGuard<T>
impl<T: ?Sized> Drop for ThreadGuard<T>
impl<T: ?Sized> Send for ThreadGuard<T>
impl<T: ?Sized> Sync for ThreadGuard<T>
Auto Trait Implementations§
impl<T> Freeze for ThreadGuard<T>
impl<T> RefUnwindSafe for ThreadGuard<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Unpin for ThreadGuard<T>
impl<T> UnwindSafe for ThreadGuard<T>where
T: UnwindSafe + ?Sized,
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