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
62
63
64
//! Boolean operations expressed as composed concrete types.

use crate::Bool;

use core::marker::PhantomData;
use crate::ops;

/// The negation of a [`Bool`].
///
/// [`Bool`]: ../trait.Bool.html
pub struct Not<A> {
    _marker: PhantomData<A>
}

impl<A: Bool> Bool for Not<A> {
    const VALUE: bool = !A::VALUE;
}

impl<A> ops::Not for Not<A> {
    type Output = A;
}

/// The logical conjunction (intersection) of two [`Bool`]s.
///
/// [`Bool`]: ../trait.Bool.html
pub struct And<A, B> {
    _marker: PhantomData<(A, B)>
}

impl<A: Bool, B: Bool> Bool for And<A, B> {
    const VALUE: bool = A::VALUE & B::VALUE;
}

impl<A, B> ops::Not for And<A, B> {
    // DeMorgan's law: !(A & B) === !A | !B
    type Output = Or<Not<A>, Not<B>>;
}

/// The logical disjunction (union) of two [`Bool`]s.
///
/// [`Bool`]: ../trait.Bool.html
pub struct Or<A, B> {
    _marker: PhantomData<(A, B)>
}

impl<A: Bool, B: Bool> Bool for Or<A, B> {
    const VALUE: bool = A::VALUE | B::VALUE;
}

impl<A, B> ops::Not for Or<A, B> {
    // DeMorgan's law: !(A | B) === !A & !B
    type Output = And<Not<A>, Not<B>>;
}

/// The exclusive disjunction of two [`Bool`]s.
///
/// [`Bool`]: ../trait.Bool.html
pub struct Xor<A, B> {
    _marker: PhantomData<(A, B)>
}

impl<A: Bool, B: Bool> Bool for Xor<A, B> {
    const VALUE: bool = A::VALUE != B::VALUE;
}