99//! Definition of `Predicate`s for comparisons of membership in a set.
1010
1111use std:: collections:: HashSet ;
12+ use std:: fmt;
1213use std:: hash:: Hash ;
1314use std:: iter:: FromIterator ;
1415
@@ -26,14 +27,14 @@ use Predicate;
2627#[ derive( Debug ) ]
2728pub struct InPredicate < T >
2829where
29- T : PartialEq ,
30+ T : PartialEq + fmt :: Debug ,
3031{
3132 inner : Vec < T > ,
3233}
3334
3435impl < T > InPredicate < T >
3536where
36- T : Ord ,
37+ T : Ord + fmt :: Debug ,
3738{
3839 /// Creates a new predicate that will return `true` when the given `variable` is
3940 /// contained with the set of items provided.
@@ -64,13 +65,22 @@ where
6465
6566impl < T > Predicate < T > for InPredicate < T >
6667where
67- T : PartialEq ,
68+ T : PartialEq + fmt :: Debug ,
6869{
6970 fn eval ( & self , variable : & T ) -> bool {
7071 self . inner . contains ( variable)
7172 }
7273}
7374
75+ impl < T > fmt:: Display for InPredicate < T >
76+ where
77+ T : PartialEq + fmt:: Debug ,
78+ {
79+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
80+ write ! ( f, "var in {:?}" , self . inner)
81+ }
82+ }
83+
7484/// Creates a new predicate that will return `true` when the given `variable` is
7585/// contained with the set of items provided.
7686///
99109/// ```
100110pub fn in_iter < I , T > ( iter : I ) -> InPredicate < T >
101111where
102- T : PartialEq ,
112+ T : PartialEq + fmt :: Debug ,
103113 I : IntoIterator < Item = T > ,
104114{
105115 InPredicate {
@@ -119,20 +129,29 @@ where
119129#[ derive( Debug ) ]
120130pub struct OrdInPredicate < T >
121131where
122- T : Ord ,
132+ T : Ord + fmt :: Debug ,
123133{
124134 inner : Vec < T > ,
125135}
126136
127137impl < T > Predicate < T > for OrdInPredicate < T >
128138where
129- T : Ord ,
139+ T : Ord + fmt :: Debug ,
130140{
131141 fn eval ( & self , variable : & T ) -> bool {
132142 self . inner . binary_search ( variable) . is_ok ( )
133143 }
134144}
135145
146+ impl < T > fmt:: Display for OrdInPredicate < T >
147+ where
148+ T : Ord + fmt:: Debug ,
149+ {
150+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
151+ write ! ( f, "var in {:?}" , self . inner)
152+ }
153+ }
154+
136155/// Predicate that returns `true` if `variable` is a member of the pre-defined
137156/// `HashSet`, otherwise returns `false`.
138157///
@@ -145,20 +164,29 @@ where
145164#[ derive( Debug ) ]
146165pub struct HashableInPredicate < T >
147166where
148- T : Hash + Eq ,
167+ T : Hash + Eq + fmt :: Debug ,
149168{
150169 inner : HashSet < T > ,
151170}
152171
153172impl < T > Predicate < T > for HashableInPredicate < T >
154173where
155- T : Hash + Eq ,
174+ T : Hash + Eq + fmt :: Debug ,
156175{
157176 fn eval ( & self , variable : & T ) -> bool {
158177 self . inner . contains ( variable)
159178 }
160179}
161180
181+ impl < T > fmt:: Display for HashableInPredicate < T >
182+ where
183+ T : Hash + Eq + fmt:: Debug ,
184+ {
185+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
186+ write ! ( f, "var in {:?}" , self . inner)
187+ }
188+ }
189+
162190/// Creates a new predicate that will return `true` when the given `variable` is
163191/// contained with the set of items provided.
164192///
@@ -181,7 +209,7 @@ where
181209/// ```
182210pub fn in_hash < I , T > ( iter : I ) -> HashableInPredicate < T >
183211where
184- T : Hash + Eq ,
212+ T : Hash + Eq + fmt :: Debug ,
185213 I : IntoIterator < Item = T > ,
186214{
187215 HashableInPredicate {
0 commit comments