Struct wayland_commons::ThreadGuard
source · 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: ?Sized> RefUnwindSafe for ThreadGuard<T>where
T: RefUnwindSafe,
impl<T: ?Sized> Unpin for ThreadGuard<T>where
T: Unpin,
impl<T: ?Sized> UnwindSafe for ThreadGuard<T>where
T: UnwindSafe,
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