1use crate::{
2 set::{DifferenceInPlace, IntersectionInPlace, UnionInPlace},
3 Difference, DisjunctiveUnion, DisjunctiveUnionInPlace, Intersection, Set, Union,
4};
5
6impl Set for bool {
8 fn is_empty(&self) -> bool {
9 !self
10 }
11
12 fn empty() -> Self {
13 false
14 }
15}
16
17impl<'v> Union<&'v bool> for bool {
18 type Output = bool;
19
20 fn union(self, rhs: &bool) -> Self::Output {
21 self || *rhs
22 }
23}
24
25impl<'v> UnionInPlace<&'v bool> for bool {
26 fn union_in_place(&mut self, rhs: &bool) {
27 *self = self.union(rhs);
28 }
29}
30
31impl<'v> Difference<&'v bool> for bool {
32 type Output = bool;
33
34 fn difference(self, rhs: &bool) -> Self::Output {
35 if *rhs {
36 false
37 } else {
38 self
39 }
40 }
41}
42
43impl<'v> DifferenceInPlace<&'v bool> for bool {
44 fn difference_in_place(&mut self, rhs: &bool) {
45 *self = self.difference(rhs);
46 }
47}
48
49impl<'v> Intersection<&'v bool> for bool {
50 type Output = bool;
51
52 fn intersection(self, rhs: &bool) -> Self::Output {
53 self && *rhs
54 }
55}
56
57impl<'v> IntersectionInPlace<&'v bool> for bool {
58 fn intersection_in_place(&mut self, rhs: &bool) {
59 *self = self.intersection(rhs);
60 }
61}
62
63impl<'v> DisjunctiveUnion<&'v bool> for bool {
64 type Output = bool;
65
66 fn disjunctive_union(self, rhs: &'v bool) -> Self::Output {
67 self ^ *rhs
68 }
69}
70
71impl<'v> DisjunctiveUnionInPlace<&'v bool> for bool {
72 fn disjunctive_union_in_place(&mut self, rhs: &'v bool) {
73 *self = self.disjunctive_union(rhs);
74 }
75}
76
77#[cfg(test)]
78mod tests {
79 use rstest::*;
80
81 #[allow(unused_imports)]
82 use super::*;
83
84 #[rstest]
85 #[case(true, true, true)]
86 #[case(false, true, true)]
87 #[case(true, false, true)]
88 #[case(false, false, false)]
89 fn union_tests(#[case] val1: bool, #[case] val2: bool, #[case] result: bool) {
90 assert_eq!(val1.union(&val2), result);
91 }
92
93 #[rstest]
94 #[case(true, true, false)]
95 #[case(false, true, false)]
96 #[case(true, false, true)]
97 #[case(false, false, false)]
98 fn difference_tests(#[case] val1: bool, #[case] val2: bool, #[case] result: bool) {
99 assert_eq!(val1.difference(&val2), result);
100 }
101
102 #[rstest]
103 #[case(true, true, true)]
104 #[case(false, true, false)]
105 #[case(true, false, false)]
106 #[case(false, false, false)]
107 fn intersection_tests(#[case] val1: bool, #[case] val2: bool, #[case] result: bool) {
108 assert_eq!(val1.intersection(&val2), result);
109 }
110
111 #[rstest]
112 #[case(true, true, false)]
113 #[case(false, true, true)]
114 #[case(true, false, true)]
115 #[case(false, false, false)]
116 fn disjunctive_union_tests(#[case] val1: bool, #[case] val2: bool, #[case] result: bool) {
117 assert_eq!(val1.disjunctive_union(&val2), result);
118 }
119}