pub struct ThreadGuard<T>(/* private fields */);Expand description
A thread guard.
A thread guard that automatically joins the thread in the destructor.
Additionally, custom pre-actions and post-actions can be defined to execute
before and after thread joining, respectively. The thread can also be
explicitly joined using the join method. In this case, the pre-action is
executed before the join, and the thread result is returned to the caller.
Implementations§
Source§impl<T> ThreadGuard<T>
impl<T> ThreadGuard<T>
Sourcepub fn new(handle: JoinHandle<T>) -> Self
pub fn new(handle: JoinHandle<T>) -> Self
Creates a new ThreadGuard.
Sourcepub fn with_pre_action<U, F>(handle: JoinHandle<T>, pre_action: F) -> Self
pub fn with_pre_action<U, F>(handle: JoinHandle<T>, pre_action: F) -> Self
Creates a new ThreadGuard with the specified pre-action.
Sourcepub fn with_post_action<F>(handle: JoinHandle<T>, post_action: F) -> Self
pub fn with_post_action<F>(handle: JoinHandle<T>, post_action: F) -> Self
Creates a new ThreadGuard with the specified post-action.
Sourcepub fn with_actions<U, F, G>(
handle: JoinHandle<T>,
pre_action: F,
post_action: G,
) -> Selfwhere
for<'a> F: FnOnce(&JoinHandle<T>) -> U + Send + 'a,
for<'a> G: FnOnce(U, ThreadResult<T>) + Send + 'a,
pub fn with_actions<U, F, G>(
handle: JoinHandle<T>,
pre_action: F,
post_action: G,
) -> Selfwhere
for<'a> F: FnOnce(&JoinHandle<T>) -> U + Send + 'a,
for<'a> G: FnOnce(U, ThreadResult<T>) + Send + 'a,
Creates a new ThreadGuard with the specified pre-action and
post-action.
Sourcepub fn join(self) -> ThreadResult<T>
pub fn join(self) -> ThreadResult<T>
Joins the guarded thread.
Trait Implementations§
Source§impl<T> Debug for ThreadGuard<T>
impl<T> Debug for ThreadGuard<T>
Auto Trait Implementations§
impl<T> Freeze for ThreadGuard<T>
impl<T> !RefUnwindSafe for ThreadGuard<T>
impl<T> Send for ThreadGuard<T>
impl<T> !Sync for ThreadGuard<T>
impl<T> Unpin for ThreadGuard<T>
impl<T> !UnwindSafe for ThreadGuard<T>
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