88
99//! Definition of boolean logic combinators over `Predicate`s.
1010
11+ use std:: marker:: PhantomData ;
12+
1113use Predicate ;
1214
1315/// Predicate that combines two `Predicate`s, returning the AND of the results.
1416///
1517/// This is created by the `Predicate::and` function.
1618#[ derive( Debug ) ]
17- pub struct AndPredicate < M1 , M2 >
19+ pub struct AndPredicate < M1 , M2 , Item >
1820where
19- M1 : Predicate ,
20- M2 : Predicate < Item = M1 :: Item > ,
21+ M1 : Predicate < Item > ,
22+ M2 : Predicate < Item > ,
23+ Item : ?Sized ,
2124{
2225 a : M1 ,
2326 b : M2 ,
27+ _phantom : PhantomData < Item > ,
2428}
2529
26- impl < M1 , M2 > AndPredicate < M1 , M2 >
30+ impl < M1 , M2 , Item > AndPredicate < M1 , M2 , Item >
2731where
28- M1 : Predicate ,
29- M2 : Predicate < Item = M1 :: Item > ,
32+ M1 : Predicate < Item > ,
33+ M2 : Predicate < Item > ,
34+ Item : ?Sized ,
3035{
3136 /// Create a new `AndPredicate` over predicates `a` and `b`.
32- pub fn new ( a : M1 , b : M2 ) -> AndPredicate < M1 , M2 > {
33- AndPredicate { a : a, b : b }
37+ pub fn new ( a : M1 , b : M2 ) -> AndPredicate < M1 , M2 , Item > {
38+ AndPredicate {
39+ a : a,
40+ b : b,
41+ _phantom : PhantomData ,
42+ }
3443 }
3544}
3645
37- impl < M1 , M2 > Predicate for AndPredicate < M1 , M2 >
46+ impl < M1 , M2 , Item > Predicate < Item > for AndPredicate < M1 , M2 , Item >
3847where
39- M1 : Predicate ,
40- M2 : Predicate < Item = M1 :: Item > ,
48+ M1 : Predicate < Item > ,
49+ M2 : Predicate < Item > ,
50+ Item : ?Sized ,
4151{
42- type Item = M1 :: Item ;
43-
44- fn eval ( & self , item : & Self :: Item ) -> bool {
52+ fn eval ( & self , item : & Item ) -> bool {
4553 self . a . eval ( item) && self . b . eval ( item)
4654 }
4755}
@@ -50,34 +58,40 @@ where
5058///
5159/// This is created by the `Predicate::or` function.
5260#[ derive( Debug ) ]
53- pub struct OrPredicate < M1 , M2 >
61+ pub struct OrPredicate < M1 , M2 , Item >
5462where
55- M1 : Predicate ,
56- M2 : Predicate < Item = M1 :: Item > ,
63+ M1 : Predicate < Item > ,
64+ M2 : Predicate < Item > ,
65+ Item : ?Sized ,
5766{
5867 a : M1 ,
5968 b : M2 ,
69+ _phantom : PhantomData < Item > ,
6070}
6171
62- impl < M1 , M2 > OrPredicate < M1 , M2 >
72+ impl < M1 , M2 , Item > OrPredicate < M1 , M2 , Item >
6373where
64- M1 : Predicate ,
65- M2 : Predicate < Item = M1 :: Item > ,
74+ M1 : Predicate < Item > ,
75+ M2 : Predicate < Item > ,
76+ Item : ?Sized ,
6677{
6778 /// Create a new `OrPredicate` over predicates `a` and `b`.
68- pub fn new ( a : M1 , b : M2 ) -> OrPredicate < M1 , M2 > {
69- OrPredicate { a : a, b : b }
79+ pub fn new ( a : M1 , b : M2 ) -> OrPredicate < M1 , M2 , Item > {
80+ OrPredicate {
81+ a : a,
82+ b : b,
83+ _phantom : PhantomData ,
84+ }
7085 }
7186}
7287
73- impl < M1 , M2 > Predicate for OrPredicate < M1 , M2 >
88+ impl < M1 , M2 , Item > Predicate < Item > for OrPredicate < M1 , M2 , Item >
7489where
75- M1 : Predicate ,
76- M2 : Predicate < Item = M1 :: Item > ,
90+ M1 : Predicate < Item > ,
91+ M2 : Predicate < Item > ,
92+ Item : ?Sized ,
7793{
78- type Item = M1 :: Item ;
79-
80- fn eval ( & self , item : & Self :: Item ) -> bool {
94+ fn eval ( & self , item : & Item ) -> bool {
8195 self . a . eval ( item) || self . b . eval ( item)
8296 }
8397}
@@ -86,30 +100,35 @@ where
86100///
87101/// This is created by the `Predicate::not` function.
88102#[ derive( Debug ) ]
89- pub struct NotPredicate < M >
103+ pub struct NotPredicate < M , Item >
90104where
91- M : Predicate ,
105+ M : Predicate < Item > ,
106+ Item : ?Sized ,
92107{
93108 inner : M ,
109+ _phantom : PhantomData < Item > ,
94110}
95111
96- impl < M > NotPredicate < M >
112+ impl < M , Item > NotPredicate < M , Item >
97113where
98- M : Predicate ,
114+ M : Predicate < Item > ,
115+ Item : ?Sized ,
99116{
100117 /// Create a new `NotPredicate` over predicate `inner`.
101- pub fn new ( inner : M ) -> NotPredicate < M > {
102- NotPredicate { inner : inner }
118+ pub fn new ( inner : M ) -> NotPredicate < M , Item > {
119+ NotPredicate {
120+ inner : inner,
121+ _phantom : PhantomData ,
122+ }
103123 }
104124}
105125
106- impl < M > Predicate for NotPredicate < M >
126+ impl < M , Item > Predicate < Item > for NotPredicate < M , Item >
107127where
108- M : Predicate ,
128+ M : Predicate < Item > ,
129+ Item : ?Sized ,
109130{
110- type Item = M :: Item ;
111-
112- fn eval ( & self , item : & Self :: Item ) -> bool {
131+ fn eval ( & self , item : & Item ) -> bool {
113132 !self . inner . eval ( item)
114133 }
115134}
0 commit comments