std_traits/
fun.rs

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
use crate::{primitive::Primitive, tuple::Tuple};

pub trait FunctionPointer: Primitive + Copy + Sized {
    type Args: Tuple;
    type Return;

    fn call(self, args: Self::Args) -> Self::Return;
}
impl<R> Primitive for fn() -> R {}
impl<R> FunctionPointer for fn() -> R {
    type Args = ();
    type Return = R;
    fn call(self, _args: Self::Args) -> Self::Return {
        self()
    }
}

impl<A1, R> Primitive for fn(A1) -> R {}
impl<A1, R> FunctionPointer for fn(A1) -> R {
    type Args = (A1,);
    type Return = R;
    fn call(self, args: Self::Args) -> Self::Return {
        self(args.0)
    }
}
impl<A1, A2, R> Primitive for fn(A1, A2) -> R {}
impl<A1, A2, R> FunctionPointer for fn(A1, A2) -> R {
    type Args = (A1, A2);
    type Return = R;
    fn call(self, args: Self::Args) -> Self::Return {
        self(args.0, args.1)
    }
}