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§
source§impl<'a> Guard<'a>
impl<'a> Guard<'a>
sourcepub fn on_scope_success<T: 'a>(
&self,
item: T,
dc: impl FnMut(T) + 'a
) -> Handle<'_, T>
pub fn on_scope_success<T: 'a>(
&self,
item: T,
dc: impl FnMut(T) + 'a
) -> Handle<'_, T>
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.
sourcepub fn on_scope_exit<T: 'a>(
&self,
item: T,
dc: impl FnMut(T) + 'a
) -> Handle<'_, T>
pub fn on_scope_exit<T: 'a>(
&self,
item: T,
dc: impl FnMut(T) + 'a
) -> Handle<'_, T>
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.
sourcepub fn on_scope_failure<T: 'a>(
&self,
item: T,
dc: impl FnMut(T) + 'a
) -> Handle<'_, T>
pub fn on_scope_failure<T: 'a>(
&self,
item: T,
dc: impl FnMut(T) + 'a
) -> Handle<'_, T>
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.