simple_ref_fn/
static_ref_function.rs1use crate::ref_fn::RefFn;
2use crate::ref_sync_fn::RefSyncFn;
3
4pub trait StaticRefFunction<'a, D, T> {
6 type Output;
8
9 fn call(data: &'a D, arg: T) -> Self::Output;
11
12 fn bind(data: &'a D) -> RefFn<'a, T, Self::Output> {
14 RefFn::new::<Self, D>(data)
15 }
16
17 fn bind_sync(data: &'a D) -> RefSyncFn<'a, T, Self::Output>
19 where
20 D: Sync,
21 {
22 RefSyncFn::new::<Self, D>(data)
23 }
24}
25
26impl<'a, T, F, R> StaticRefFunction<'a, F, T> for F
27where
28 F: Fn(T) -> R,
29{
30 type Output = R;
31
32 fn call(data: &'a Self, arg: T) -> Self::Output {
33 (*data)(arg)
34 }
35}