Struct glib::thread_guard::ThreadGuard
source · pub struct ThreadGuard<T> {
thread_id: usize,
value: T,
}
Expand description
Thread guard that only gives access to the contained value on the thread it was created on.
Fields§
§thread_id: usize
§value: T
Implementations§
source§impl<T> ThreadGuard<T>
impl<T> ThreadGuard<T>
sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Create a new thread guard around value
.
The thread guard ensures that access to the value is only allowed from the thread it was created on, and otherwise panics.
The thread guard implements the Send
trait even if the contained value does not.
sourcepub fn get_ref(&self) -> &T
pub fn get_ref(&self) -> &T
Return a reference to the contained value from the thread guard.
§Panics
This function panics if called from a different thread than where the thread guard was created.
sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Return a mutable reference to the contained value from the thread guard.
§Panics
This function panics if called from a different thread than where the thread guard was created.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Return the contained value from the thread guard.
§Panics
This function panics if called from a different thread than where the thread guard was created.