typebool/
comp.rs

1//! Boolean operations expressed as composed concrete types.
2
3use crate::Bool;
4
5use core::marker::PhantomData;
6use crate::ops;
7
8/// The negation of a [`Bool`].
9///
10/// [`Bool`]: ../trait.Bool.html
11pub struct Not<A> {
12    _marker: PhantomData<A>
13}
14
15impl<A: Bool> Bool for Not<A> {
16    const VALUE: bool = !A::VALUE;
17}
18
19impl<A> ops::Not for Not<A> {
20    type Output = A;
21}
22
23/// The logical conjunction (intersection) of two [`Bool`]s.
24///
25/// [`Bool`]: ../trait.Bool.html
26pub struct And<A, B> {
27    _marker: PhantomData<(A, B)>
28}
29
30impl<A: Bool, B: Bool> Bool for And<A, B> {
31    const VALUE: bool = A::VALUE & B::VALUE;
32}
33
34impl<A, B> ops::Not for And<A, B> {
35    // DeMorgan's law: !(A & B) === !A | !B
36    type Output = Or<Not<A>, Not<B>>;
37}
38
39/// The logical disjunction (union) of two [`Bool`]s.
40///
41/// [`Bool`]: ../trait.Bool.html
42pub struct Or<A, B> {
43    _marker: PhantomData<(A, B)>
44}
45
46impl<A: Bool, B: Bool> Bool for Or<A, B> {
47    const VALUE: bool = A::VALUE | B::VALUE;
48}
49
50impl<A, B> ops::Not for Or<A, B> {
51    // DeMorgan's law: !(A | B) === !A & !B
52    type Output = And<Not<A>, Not<B>>;
53}
54
55/// The exclusive disjunction of two [`Bool`]s.
56///
57/// [`Bool`]: ../trait.Bool.html
58pub struct Xor<A, B> {
59    _marker: PhantomData<(A, B)>
60}
61
62impl<A: Bool, B: Bool> Bool for Xor<A, B> {
63    const VALUE: bool = A::VALUE != B::VALUE;
64}