Struct ThreadGuard
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§
§impl<T> ThreadGuard<T>
impl<T> ThreadGuard<T>
pub fn new(value: T) -> ThreadGuard<T>
pub fn new(value: T) -> ThreadGuard<T>
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.
pub 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.
pub 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.
pub 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.
Trait Implementations§
§impl<T> Deref for ThreadGuard<T>
impl<T> Deref for ThreadGuard<T>
§impl<T> DerefMut for ThreadGuard<T>
impl<T> DerefMut for ThreadGuard<T>
§fn deref_mut(&mut self) -> &mut <ThreadGuard<T> as Deref>::Target
fn deref_mut(&mut self) -> &mut <ThreadGuard<T> as Deref>::Target
impl<T> Send for ThreadGuard<T>
impl<T> Sync for ThreadGuard<T>
Auto Trait Implementations§
impl<T> Freeze for ThreadGuard<T>where
T: Freeze,
impl<T> RefUnwindSafe for ThreadGuard<T>where
T: RefUnwindSafe,
impl<T> Unpin for ThreadGuard<T>where
T: Unpin,
impl<T> 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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more