pub trait ModeWrapper<'m, T: 'm> {
// Required method
fn wrap(
self: Arc<Self>,
task: Box<dyn FnOnce() -> T + 'm>,
) -> Box<dyn FnOnce() -> T + 'm>;
// Provided method
fn into_combiner(self) -> Box<dyn ModeCombiner<'m, T> + Send + Sync + 'm>
where Self: Sized + Send + Sync + 'm { ... }
}Expand description
Trait to implement in order to apply a mode to a task. ModeWrappers are supplied to a Mode
using Mode::with where they might be combined with other ModeWrappers
using the ModeCombiner supplied by ModeWrapper::into_combiner.
Unlike Invokers, Modes and ModeWrappers are generic over the return type
of the tasks they may wrap and thus can directly interact with the return value of the task.
This also means that the lifetime of the Mode is tied to the lifetime of the type they are generic over.
Required Methods§
Provided Methods§
Sourcefn into_combiner(self) -> Box<dyn ModeCombiner<'m, T> + Send + Sync + 'm>
fn into_combiner(self) -> Box<dyn ModeCombiner<'m, T> + Send + Sync + 'm>
Consume this ModeWrapper and produce a ModeCombiner. This is used by
Mode::with to be able to combine several ModeWrappers and can
reference back to this ModeWrapper to wrap tasks when applying a Mode to a task. Combining
ModeWrappers is implemented by a separate trait to be able to provide a default implementation
in DelegatingModeCombiner that combines ModeCombiners by
setting the current ModeCombiner as the outer ModeCombiner of the newly added ModeCombiner
so that the iterator walks the ModeCombiners in the reverse order of which they were added, meaning
the ModeCombiner that was added first ends up wrapping the task last, meaning its task will be the
outermost task.