snarkvm_console_types_boolean/
bitwise.rs1use super::*;
17
18impl<E: Environment> Equal for Boolean<E> {
19 type Output = Boolean<E>;
20
21 fn is_equal(&self, other: &Self) -> Self::Output {
23 Boolean::new(self == other)
24 }
25
26 fn is_not_equal(&self, other: &Self) -> Self::Output {
28 Boolean::new(self != other)
29 }
30}
31
32impl<E: Environment> Not for Boolean<E> {
33 type Output = Boolean<E>;
34
35 #[inline]
37 fn not(self) -> Self::Output {
38 Boolean::new(!self.boolean)
39 }
40}
41
42impl<E: Environment> BitAnd<Boolean<E>> for Boolean<E> {
43 type Output = Boolean<E>;
44
45 #[inline]
47 fn bitand(self, other: Self) -> Self::Output {
48 Boolean::new(self.boolean & other.boolean)
49 }
50}
51
52impl<E: Environment> BitAnd<&Boolean<E>> for Boolean<E> {
53 type Output = Boolean<E>;
54
55 #[inline]
57 fn bitand(self, other: &Boolean<E>) -> Self::Output {
58 Boolean::new(self.boolean & other.boolean)
59 }
60}
61
62impl<E: Environment> BitAndAssign for Boolean<E> {
63 #[inline]
65 fn bitand_assign(&mut self, other: Self) {
66 *self = Boolean::new(self.boolean & other.boolean)
67 }
68}
69
70impl<E: Environment> BitOr for Boolean<E> {
71 type Output = Boolean<E>;
72
73 #[inline]
75 fn bitor(self, other: Self) -> Self::Output {
76 Boolean::new(self.boolean | other.boolean)
77 }
78}
79
80impl<E: Environment> BitOr<&Boolean<E>> for Boolean<E> {
81 type Output = Boolean<E>;
82
83 #[inline]
85 fn bitor(self, other: &Boolean<E>) -> Self::Output {
86 Boolean::new(self.boolean | other.boolean)
87 }
88}
89
90impl<E: Environment> BitOrAssign for Boolean<E> {
91 #[inline]
93 fn bitor_assign(&mut self, other: Self) {
94 *self = Boolean::new(self.boolean | other.boolean)
95 }
96}
97
98impl<E: Environment> BitXor for Boolean<E> {
99 type Output = Boolean<E>;
100
101 #[inline]
103 fn bitxor(self, other: Self) -> Self::Output {
104 Boolean::new(self.boolean ^ other.boolean)
105 }
106}
107
108impl<E: Environment> BitXor<&Boolean<E>> for Boolean<E> {
109 type Output = Boolean<E>;
110
111 #[inline]
113 fn bitxor(self, other: &Boolean<E>) -> Self::Output {
114 Boolean::new(self.boolean ^ other.boolean)
115 }
116}
117
118impl<E: Environment> BitXorAssign for Boolean<E> {
119 #[inline]
121 fn bitxor_assign(&mut self, other: Self) {
122 *self = Boolean::new(self.boolean ^ other.boolean)
123 }
124}
125
126impl<E: Environment> Nand for Boolean<E> {
127 type Output = Boolean<E>;
128
129 #[inline]
131 fn nand(&self, other: &Self) -> Self::Output {
132 Boolean::new(!(self.boolean & other.boolean))
133 }
134}
135
136impl<E: Environment> Nor for Boolean<E> {
137 type Output = Boolean<E>;
138
139 #[inline]
141 fn nor(&self, other: &Self) -> Self::Output {
142 Boolean::new(!(self.boolean | other.boolean))
143 }
144}
145
146impl<E: Environment> Ternary for Boolean<E> {
147 type Boolean = Boolean<E>;
148 type Output = Self;
149
150 fn ternary(condition: &Self::Boolean, first: &Self, second: &Self) -> Self::Output {
152 match **condition {
153 true => *first,
154 false => *second,
155 }
156 }
157}