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
/*
    Appellation: func <mod>
    Contrib: FL03 <jo3mccain@icloud.com>
*/
pub use self::structural::*;

pub(crate) mod structural;

pub trait FnHandler<Args> {
    type Output;

    fn item_fn(&self) -> fn(Args) -> Self::Output;
}

#[allow(unused)]
#[cfg(test)]
mod tests {
    use super::FnHandler;
    use core::ops::Mul;

    pub struct Sample;

    impl Sample {
        pub fn sqr<T>(x: T) -> T
        where
            T: Copy + Mul<T, Output = T>,
        {
            x * x
        }

        pub fn blahblah<T>() -> fn(T) -> T
        where
            T: Copy + Mul<T, Output = T>,
        {
            Sample::sqr
        }
    }

    impl<T> FnHandler<T> for Sample
    where
        T: Copy + Mul<T, Output = T>,
    {
        type Output = T;

        fn item_fn(&self) -> fn(T) -> T {
            Self::sqr
        }
    }

    #[test]
    fn test_fn_handler() {
        let sample = Sample;
        let item_fn = sample.item_fn();
        assert_eq!(item_fn(2), 4);
    }
}