1use std::ops::{Not, BitAnd, BitOr};
28
29pub enum True {}
31
32pub enum False {}
34
35pub enum Unknown {}
37
38#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
40pub enum Ternary {
41 T,
43 U,
45 F,
47}
48
49pub trait ToTernary {
59 fn to_ternary() -> Ternary;
60}
61
62impl ToTernary for True {
63 #[inline] fn to_ternary() -> Ternary { Ternary::T }
64}
65
66impl ToTernary for False {
67 #[inline] fn to_ternary() -> Ternary { Ternary::F }
68}
69
70impl ToTernary for Unknown {
71 #[inline] fn to_ternary() -> Ternary { Ternary::U }
72}
73
74impl Not for True {
78 type Output = False;
79 fn not(self) -> Self::Output { unreachable!() }
80}
81
82impl Not for False {
84 type Output = True;
85 fn not(self) -> Self::Output { unreachable!() }
86}
87
88impl Not for Unknown {
90 type Output = Unknown;
91 fn not(self) -> Self::Output { unreachable!() }
92}
93
94impl<X: ToTernary> BitAnd<X> for True {
98 type Output = X;
99 fn bitand(self, _: X) -> Self::Output { unreachable!() }
100}
101
102impl<X: ToTernary> BitAnd<X> for False {
104 type Output = False;
105 fn bitand(self, _: X) -> Self::Output { unreachable!() }
106}
107
108impl BitAnd<True> for Unknown {
110 type Output = Unknown;
111 fn bitand(self, _: True) -> Self::Output { unreachable!() }
112}
113
114impl BitAnd<Unknown> for Unknown {
116 type Output = Unknown;
117 fn bitand(self, _: Unknown) -> Self::Output { unreachable!() }
118}
119
120impl BitAnd<False> for Unknown {
122 type Output = False;
123 fn bitand(self, _: False) -> Self::Output { unreachable!() }
124}
125
126
127impl<X: ToTernary> BitOr<X> for True {
131 type Output = True;
132 fn bitor(self, _: X) -> Self::Output { unreachable!() }
133}
134
135impl<X: ToTernary> BitOr<X> for False {
137 type Output = X;
138 fn bitor(self, _: X) -> Self::Output { unreachable!() }
139}
140
141impl BitOr<True> for Unknown {
143 type Output = True;
144 fn bitor(self, _: True) -> Self::Output { unreachable!() }
145}
146
147impl BitOr<Unknown> for Unknown {
149 type Output = Unknown;
150 fn bitor(self, _: Unknown) -> Self::Output { unreachable!() }
151}
152
153impl BitOr<False> for Unknown {
155 type Output = Unknown;
156 fn bitor(self, _: False) -> Self::Output { unreachable!() }
157}
158
159pub trait Same<Rhs = Self> {
161 type Output;
162}
163
164impl<T> Same<T> for T {
165 type Output = T;
166}