pub struct ThreadGuard<T> { /* private fields */ }
Expand description
Thread guard that only gives access to the contained value on the thread it was created on.
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.