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