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
/*
   Appellation: binary <mod>
   Contrib: FL03 <jo3mccain@icloud.com>
*/
pub use self::{arithmetic::*, kinds::*, operator::*, specs::*};

pub(crate) mod arithmetic;
pub(crate) mod kinds;
pub(crate) mod operator;
pub(crate) mod specs;

pub type BoxedBinOp<A, B = A, C = A> = Box<dyn BinOp<A, B, Output = C>>;

#[derive(Clone, Debug)]
#[allow(dead_code)]
enum Bop<Kind>
where
    Kind: BinaryOperand,
{
    Custom { name: String, op: Kind },
}

#[allow(dead_code)]
pub(crate) trait BinaryOperand {
    type Args: BinArgs;
    type Output;

    fn eval(
        &self,
        lhs: <Self::Args as BinArgs>::Lhs,
        rhs: <Self::Args as BinArgs>::Rhs,
    ) -> Self::Output;
}

pub trait BinOp<A, B = A> {
    type Output;

    fn eval(&self, lhs: A, rhs: B) -> Self::Output;
}

impl<S, A, B, C> BinOp<A, B> for S
where
    S: Fn(A, B) -> C,
{
    type Output = C;

    fn eval(&self, lhs: A, rhs: B) -> Self::Output {
        self(lhs, rhs)
    }
}

impl<A, B, C> BinOp<A, B> for Box<dyn BinOp<A, B, Output = C>> {
    type Output = C;

    fn eval(&self, lhs: A, rhs: B) -> Self::Output {
        self.as_ref().eval(lhs, rhs)
    }
}

#[cfg(test)]
mod tests {}