@@ -222,6 +222,70 @@ impl IntoPathPredicate<StrContentPathPredicate> for &'static str {
222
222
}
223
223
}
224
224
225
+ // Keep `predicates` concrete Predicates out of our public API.
226
+ /// Predicate used by `IntoPathPredicate` for `str`
227
+ #[ derive( Debug , Clone ) ]
228
+ pub struct StrPathPredicate < P : predicates_core:: Predicate < str > > (
229
+ predicates:: path:: FileContentPredicate <
230
+ predicates:: str:: Utf8Predicate < P > ,
231
+ > ,
232
+ ) ;
233
+
234
+ impl < P > StrPathPredicate < P >
235
+ where
236
+ P : predicates_core:: Predicate < str > ,
237
+ {
238
+ pub ( crate ) fn new ( value : P ) -> Self {
239
+ let pred = value. from_utf8 ( ) . from_file_path ( ) ;
240
+ StrPathPredicate ( pred)
241
+ }
242
+ }
243
+
244
+ impl < P > predicates_core:: reflection:: PredicateReflection for StrPathPredicate < P >
245
+ where
246
+ P : predicates_core:: Predicate < str > ,
247
+ {
248
+ fn parameters < ' a > (
249
+ & ' a self ,
250
+ ) -> Box < Iterator < Item = predicates_core:: reflection:: Parameter < ' a > > + ' a > {
251
+ self . 0 . parameters ( )
252
+ }
253
+
254
+ /// Nested `Predicate`s of the current `Predicate`.
255
+ fn children < ' a > ( & ' a self ) -> Box < Iterator < Item = predicates_core:: reflection:: Child < ' a > > + ' a > {
256
+ self . 0 . children ( )
257
+ }
258
+ }
259
+
260
+ impl < P > predicates_core:: Predicate < path:: Path > for StrPathPredicate < P >
261
+ where
262
+ P : predicates_core:: Predicate < str > ,
263
+ {
264
+ fn eval ( & self , item : & path:: Path ) -> bool {
265
+ self . 0 . eval ( item)
266
+ }
267
+ }
268
+
269
+ impl < P > fmt:: Display for StrPathPredicate < P >
270
+ where
271
+ P : predicates_core:: Predicate < str > ,
272
+ {
273
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
274
+ self . 0 . fmt ( f)
275
+ }
276
+ }
277
+
278
+ impl < P > IntoPathPredicate < StrPathPredicate < P > > for P
279
+ where
280
+ P : predicates_core:: Predicate < str > ,
281
+ {
282
+ type Predicate = StrPathPredicate < P > ;
283
+
284
+ fn into_path ( self ) -> Self :: Predicate {
285
+ Self :: Predicate :: new ( self )
286
+ }
287
+ }
288
+
225
289
#[ cfg( test) ]
226
290
mod test {
227
291
use super :: * ;
0 commit comments