Struct scoped::Guard

source ·
pub struct Guard<'a> { /* private fields */ }
Expand description

A guard is a handle to schedule closures on.

A guard can schedule 2 closure types, closures that take no arguments, and closures that take 1 argument.

Scheduling a closure that takes no arguments, can be done trough the following methods:

These methods return a Handle, through which cancelling of the scheduled closure is possible.

Scheduling a closure that takes 1 argument, can be done trough the following methods:

These methods also take the argument they are going to be called with, and return a Handle. The Handle can be used to cancel the scheduled closure, as well as accessing the given argument trough Deref and DerefMut

Its important to note that closures scheduled with Guard::on_scope_exit and Guard::on_scope_exit_with, will always run, and will always run after all closures scheduled to run on success or failure are executed.

The last scheduled closure gets runned first.

Implementations§

Schedules deferred closure dc to run on a scope’s success. The deferred closure can be cancelled using Handle::cancel,

Schedules deferred closure dc to run on a scope’s exit. The deferred closure can be cancelled using Handle::cancel,

Schedules deferred closure dc to run on a scope’s failure. The deferred closure can be cancelled using Handle::cancel,

Schedules deferred closure dc to run on a scope’s exit. The deferred closure can be cancelled using Handle::cancel, returning the value the closure was going to be called with.

Schedules deferred closure dc to run on a scope’s failure. The deferred closure can be cancelled using Handle::cancel, returning the value the closure was going to be called with.

Schedules deferred closure dc to run on a scope’s success. The deferred closure can be cancelled using Handle::cancel, returning the value the closure was going to be called with.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.