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
use std::ops::{BitXor, BitXorAssign};
use ::*;

impl <T> BitXor<T> for Expr where T: Into<Expr> {
    type Output = Expr;
    fn bitxor(self, rhs: T) -> Expr {
        Expr::Pow(Box::new(self.clone()), Box::new(rhs.into()))
    }
}

impl <T> BitXorAssign<T> for Expr where T: Into<Expr> {
    fn bitxor_assign(&mut self, rhs: T) {
        *self = self.clone() ^ rhs.into()
    }
}

impl BitXor<Expr> for f64 {
    type Output = Expr;
    fn bitxor(self, rhs: Expr) -> Expr {
        Expr::Num(self) ^ rhs.clone()
    }
}

impl BitXor<Expr> for i64 {
    type Output = Expr;
    fn bitxor(self, rhs: Expr) -> Expr {
        Expr::Num(self as f64) ^ rhs.clone()
    }
}

#[test]
fn expr_f64() {
    let expd = s!(x)^2;
    assert_eq!(format!("{:?}", expd), "Pow(Symbol(\"x\"), Num(2.0))");
}

#[test]
fn f64_expr() {
    let expd = 10^s!(x);
    assert_eq!(format!("{:?}", expd), "Pow(Num(10.0), Symbol(\"x\"))");
}

#[test]
fn expr_expr() {
    let expd = s!(x) ^ s!(y);
    assert_eq!(format!("{:?}", expd), "Pow(Symbol(\"x\"), Symbol(\"y\"))");
}