Struct scoped::Guard

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

A guard is a handle to schedule closures on. Scheduling a closure takes a closure with 1 parameter, and the parameter it is going to be called with. It returns a Handle to the parameter, so it’s still usable within the scope. A Handle implements Deref and DerefMut, to access the parameter. To cancel a callback, Handle::cancel should be called.

Its important to note that closures scheduled with Guard::on_scope_exit 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 defered 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.

Schedules defered 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 defered 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.

Trait Implementations§

Returns the “default value” for a type. Read more

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.