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
//! Unary operators.

use Secret;

pub trait Neg {
    type Output;

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

impl<'a, T: Neg> Neg for &'a T {
    type Output = T::Output;

    fn neg(&self) -> T::Output {(*self).neg()}
}

impl Neg for f64 {
    type Output = f64;

    fn neg(&self) -> f64 {
        -self
    }
}

pub fn neg<T: Neg>(a: &T) -> T::Output {
    a.neg()
}

pub trait Not {
    type Output;

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

impl<'a, T: Not> Not for &'a T {
    type Output = <T as Not>::Output;

    fn not(&self) -> Self::Output {
        (*self).not()
    }
}

impl Not for bool {
    type Output = bool;

    fn not(&self) -> bool {
        !self
    }
}

impl<A: Clone> Not for Secret<bool, A> {
    type Output = Secret<bool, A>;

    fn not(&self) -> Secret<bool, A> {
        Secret {val: !self.val, secret: self.secret.clone()}
    }
}

pub fn not<T: Not>(a: &T) -> T::Output {
    a.not()
}