roopes_core/primitives/executable/lambda.rs
1//! Provides a simple wrapper struct around
2//! [`Delegate`], `Fn()` types.
3use super::Executable;
4
5/// An [`Executable`] [`Delegate`] takes no
6/// parameters and returns nothing.
7pub trait Delegate = Fn();
8
9/// Defines an encapsulated [`Executable`] as a
10/// struct, which just delegates its execution to
11/// the attached [`Delegate`].
12pub struct Lambda<D>
13where
14 D: Delegate,
15{
16 delegate: D,
17}
18
19impl<D> Lambda<D>
20where
21 D: Delegate,
22{
23 /// Creates a [`Lambda`] from a given
24 /// [`Delegate`].
25 pub fn new(delegate: D) -> Self
26 {
27 Self { delegate }
28 }
29}
30
31impl<D> Executable for Lambda<D>
32where
33 D: Delegate,
34{
35 fn execute(&self)
36 {
37 (self.delegate)();
38 }
39}