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§
source§impl<'a> Guard<'a>
impl<'a> Guard<'a>
sourcepub fn on_scope_success<'s, F: FnOnce() + 'a>(
&'s self,
dc: F
) -> Handle<'s, (), impl FnOnce(()) + 'a>
pub fn on_scope_success<'s, F: FnOnce() + 'a>(
&'s self,
dc: F
) -> Handle<'s, (), impl FnOnce(()) + 'a>
Schedules deferred closure dc
to run on a scope’s success.
The deferred closure can be cancelled using Handle::cancel
,
sourcepub fn on_scope_exit<'s, F: FnOnce() + 'a>(
&'s self,
dc: F
) -> Handle<'s, (), impl FnOnce(())>
pub fn on_scope_exit<'s, F: FnOnce() + 'a>(
&'s self,
dc: F
) -> Handle<'s, (), impl FnOnce(())>
Schedules deferred closure dc
to run on a scope’s exit.
The deferred closure can be cancelled using Handle::cancel
,
sourcepub fn on_scope_failure<'s, F: FnOnce() + 'a>(
&'s self,
dc: F
) -> Handle<'s, (), impl FnOnce(())>
pub fn on_scope_failure<'s, F: FnOnce() + 'a>(
&'s self,
dc: F
) -> Handle<'s, (), impl FnOnce(())>
Schedules deferred closure dc
to run on a scope’s failure.
The deferred closure can be cancelled using Handle::cancel
,
sourcepub fn on_scope_exit_with<'s, T: 'a, F: FnOnce(T) + 'a>(
&'s self,
item: T,
dc: F
) -> Handle<'s, T, F>
pub fn on_scope_exit_with<'s, T: 'a, F: FnOnce(T) + 'a>(
&'s self,
item: T,
dc: F
) -> Handle<'s, T, F>
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.
sourcepub fn on_scope_failure_with<'s, T: 'a, F: FnOnce(T) + 'a>(
&'s self,
item: T,
dc: F
) -> Handle<'s, T, F>
pub fn on_scope_failure_with<'s, T: 'a, F: FnOnce(T) + 'a>(
&'s self,
item: T,
dc: F
) -> Handle<'s, T, F>
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.
sourcepub fn on_scope_success_with<'s, T: 'a, F: FnOnce(T) + 'a>(
&'s self,
item: T,
dc: F
) -> Handle<'s, T, F>
pub fn on_scope_success_with<'s, T: 'a, F: FnOnce(T) + 'a>(
&'s self,
item: T,
dc: F
) -> Handle<'s, T, F>
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.