redact/
ops.rs

1use crate::Secret;
2
3use core::ops;
4
5macro_rules! ops {
6    { ($type:tt, $trait:ident, $method:ident), $($tt:tt)* } => {
7        ops!(($type, $trait, $method));
8        ops!($($tt)*);
9    };
10    { (binary, $trait:ident, $method:ident)} => {
11        impl<T, U> ops::$trait<Secret<U>> for Secret<T>
12        where
13            T: ops::$trait<U>,
14        {
15            type Output = Secret<T::Output>;
16            #[inline]
17            fn $method(self, rhs: Secret<U>) -> Self::Output {
18                Secret(self.0.$method(rhs.0))
19            }
20        }
21    };
22    { (assign, $trait:ident, $method:ident)} => {
23        impl<T, U> ops::$trait<Secret<U>> for Secret<T>
24        where
25            T: ops::$trait<U>,
26        {
27            #[inline]
28            fn $method(&mut self, rhs: Secret<U>) {
29                self.0.$method(rhs.0)
30            }
31        }
32    };
33    { (unary, $trait:ident, $method:ident)} => {
34        impl<T> ops::$trait for Secret<T>
35        where
36            T: ops::$trait,
37        {
38            type Output = Secret<T::Output>;
39            #[inline]
40            fn $method(self) -> Self::Output {
41                Secret(self.0.$method())
42            }
43        }
44    };
45    () => ()
46}
47
48ops! {
49    (binary, Add, add),
50    (assign, AddAssign, add_assign),
51    (binary, BitAnd, bitand),
52    (assign, BitAndAssign, bitand_assign),
53    (binary, BitOr, bitor),
54    (assign, BitOrAssign, bitor_assign),
55    (binary, BitXor, bitxor),
56    (assign, BitXorAssign, bitxor_assign),
57    (binary, Div, div),
58    (assign, DivAssign, div_assign),
59    (binary, Mul, mul),
60    (assign, MulAssign, mul_assign),
61    (binary, Rem, rem),
62    (assign, RemAssign, rem_assign),
63    (binary, Shl, shl),
64    (assign, ShlAssign, shl_assign),
65    (binary, Shr, shr),
66    (assign, ShrAssign, shr_assign),
67    (binary, Sub, sub),
68    (assign, SubAssign, sub_assign),
69    (unary, Neg, neg),
70    (unary, Not, not),
71}