pub struct ThreadBound<T> { /* private fields */ }
Expand description
ThreadBound is a Sync-maker and Send-maker that allows accessing a value of type T only from the original thread on which the ThreadBound was constructed.
Refer to the crate-level documentation for a usage example.
Implementations§
Source§impl<T> ThreadBound<T>
impl<T> ThreadBound<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Binds a value to the current thread. The wrapper can be sent around to other threads, but no other threads will be able to access the underlying value.
Sourcepub fn get_ref(&self) -> Option<&T>
pub fn get_ref(&self) -> Option<&T>
Accesses a reference to the underlying value if this is its original
thread, otherwise None
.
Sourcepub fn get_mut(&mut self) -> Option<&mut T>
pub fn get_mut(&mut self) -> Option<&mut T>
Accesses a mutable reference to the underlying value if this is its
original thread, otherwise None
.
Sourcepub fn into_inner(self) -> Option<T>
pub fn into_inner(self) -> Option<T>
Extracts ownership of the underlying value if this is its original
thread, otherwise None
.
Trait Implementations§
Source§impl<T: Debug> Debug for ThreadBound<T>
impl<T: Debug> Debug for ThreadBound<T>
Source§impl<T: Default> Default for ThreadBound<T>
impl<T: Default> Default for ThreadBound<T>
impl<T: Copy> Send for ThreadBound<T>
impl<T> Sync for ThreadBound<T>
Auto Trait Implementations§
impl<T> Freeze for ThreadBound<T>where
T: Freeze,
impl<T> RefUnwindSafe for ThreadBound<T>where
T: RefUnwindSafe,
impl<T> Unpin for ThreadBound<T>where
T: Unpin,
impl<T> UnwindSafe for ThreadBound<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