reactive_graph/effect/
effect_function.rs

1/// Trait to enable effect functions that have zero or one parameter
2pub trait EffectFunction<T, M> {
3    /// Call this to execute the function. In case the actual function has no parameters
4    /// the parameter `p` will simply be ignored.
5    fn run(&mut self, p: Option<T>) -> T;
6}
7
8/// Marker for single parameter functions
9pub struct SingleParam;
10/// Marker for no parameter functions
11pub struct NoParam;
12
13impl<Func, T> EffectFunction<T, SingleParam> for Func
14where
15    Func: FnMut(Option<T>) -> T,
16{
17    #[inline(always)]
18    fn run(&mut self, p: Option<T>) -> T {
19        (self)(p)
20    }
21}
22
23impl<Func> EffectFunction<(), NoParam> for Func
24where
25    Func: FnMut(),
26{
27    #[inline(always)]
28    fn run(&mut self, _: Option<()>) {
29        self()
30    }
31}