ThreadGuard

Struct ThreadGuard 

Source
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>

Source

pub fn new(handle: JoinHandle<T>) -> Self

Creates a new ThreadGuard.

Source

pub fn with_pre_action<U, F>(handle: JoinHandle<T>, pre_action: F) -> Self
where for<'a> F: FnOnce(&JoinHandle<T>) -> U + Send + 'a,

Creates a new ThreadGuard with the specified pre-action.

Source

pub fn with_post_action<F>(handle: JoinHandle<T>, post_action: F) -> Self
where for<'a> F: FnOnce(ThreadResult<T>) + Send + 'a,

Creates a new ThreadGuard with the specified post-action.

Source

pub fn with_actions<U, F, G>( handle: JoinHandle<T>, pre_action: F, post_action: G, ) -> Self
where 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.

Source

pub fn join(self) -> ThreadResult<T>

Joins the guarded thread.

Trait Implementations§

Source§

impl<T> Debug for ThreadGuard<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for ThreadGuard<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.