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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/// Substitution for FnMut trait family in stable and beta channels
/// In nightly consider to use "nightly" feature and FnMut trait family
pub trait HetFnOnce<A> {
    /// Output of the function
    type Output;

    /// Call the function
    fn call_once(self, arg: A) -> Self::Output;
}

/// Substitution for FnMut trait family in stable and beta channels
/// In nightly consider to use "nightly" feature and FnMut trait family
pub trait HetFnMut<A>: HetFnOnce<A> {
    /// Call the function
    fn call_mut(&mut self, arg: A) -> Self::Output;
}

impl<'a, A, X> HetFnOnce<A> for &'a mut X
    where X: HetFnMut<A>
{
    type Output = <X as HetFnOnce<A>>::Output;
    fn call_once(self, arg: A) -> Self::Output {
        X::call_mut(self, arg)
    }
}

impl<'a, A, X> HetFnMut<A> for &'a mut X
    where X: HetFnMut<A>
{
    fn call_mut(&mut self, arg: A) -> Self::Output {
        X::call_mut(self, arg)
    }
}

/// Substitution for Fn trait family in stable and beta channels
/// In nightly consider to use "nightly" feature and Fn trait family
pub trait HetFn<A>: HetFnMut<A> {
    /// Call the function
    fn call(&self, arg: A) -> Self::Output;
}

impl<'a, A, X> HetFnOnce<A> for &'a X
    where X: HetFn<A>
{
    type Output = <X as HetFnOnce<A>>::Output;
    fn call_once(self, arg: A) -> Self::Output {
        X::call(self, arg)
    }
}

impl<'a, A, X> HetFnMut<A> for &'a X
    where X: HetFn<A>
{
    fn call_mut(&mut self, arg: A) -> Self::Output {
        X::call(self, arg)
    }
}

impl<'a, A, X> HetFn<A> for &'a X
    where X: HetFn<A>
{
    fn call(&self, arg: A) -> Self::Output {
        X::call(self, arg)
    }
}