@@ -405,7 +405,7 @@ where
405
405
}
406
406
407
407
// Keep `predicates` concrete Predicates out of our public API.
408
- /// [Predicate] used by [`IntoCodePredicate`] for bytes .
408
+ /// [Predicate] used by [`IntoCodePredicate`] for code .
409
409
///
410
410
/// [`IntoCodePredicate`]: trait.IntoCodePredicate.html
411
411
/// [Predicate]: https://docs.rs/predicates-core/0.9.0/predicates_core/trait.Predicate.html
@@ -461,7 +461,7 @@ impl IntoCodePredicate<EqCodePredicate> for i32 {
461
461
}
462
462
463
463
// Keep `predicates` concrete Predicates out of our public API.
464
- /// [Predicate] used by [`IntoCodePredicate`] for bytes .
464
+ /// [Predicate] used by [`IntoCodePredicate`] for iterables of codes .
465
465
///
466
466
/// [`IntoCodePredicate`]: trait.IntoCodePredicate.html
467
467
/// [Predicate]: https://docs.rs/predicates-core/0.9.0/predicates_core/trait.Predicate.html
@@ -691,6 +691,75 @@ impl IntoOutputPredicate<StrContentOutputPredicate> for &'static str {
691
691
}
692
692
}
693
693
694
+ // Keep `predicates` concrete Predicates out of our public API.
695
+ /// [Predicate] used by [`IntoOutputPredicate`] for [`Predicate<str>`].
696
+ ///
697
+ /// [`IntoOutputPredicate`]: trait.IntoOutputPredicate.html
698
+ /// [Predicate]: https://docs.rs/predicates-core/0.9.0/predicates_core/trait.Predicate.html
699
+ #[ derive( Debug , Clone ) ]
700
+ pub struct StrOutputPredicate < P : predicates_core:: Predicate < str > >
701
+ (
702
+ predicates:: str:: Utf8Predicate < P > ,
703
+ ) ;
704
+
705
+ impl < P > StrOutputPredicate < P >
706
+ where P : predicates_core:: Predicate < str >
707
+ {
708
+ pub ( crate ) fn new ( pred : P ) -> Self {
709
+ let pred = pred. from_utf8 ( ) ;
710
+ StrOutputPredicate ( pred)
711
+ }
712
+ }
713
+
714
+ impl < P > predicates_core:: reflection:: PredicateReflection for StrOutputPredicate < P >
715
+ where P : predicates_core:: Predicate < str >
716
+ {
717
+ fn parameters < ' a > (
718
+ & ' a self ,
719
+ ) -> Box < Iterator < Item = predicates_core:: reflection:: Parameter < ' a > > + ' a > {
720
+ self . 0 . parameters ( )
721
+ }
722
+
723
+ /// Nested `Predicate`s of the current `Predicate`.
724
+ fn children < ' a > ( & ' a self ) -> Box < Iterator < Item = predicates_core:: reflection:: Child < ' a > > + ' a > {
725
+ self . 0 . children ( )
726
+ }
727
+ }
728
+
729
+ impl < P > predicates_core:: Predicate < [ u8 ] > for StrOutputPredicate < P >
730
+ where P : predicates_core:: Predicate < str >
731
+ {
732
+ fn eval ( & self , item : & [ u8 ] ) -> bool {
733
+ self . 0 . eval ( item)
734
+ }
735
+
736
+ fn find_case < ' a > (
737
+ & ' a self ,
738
+ expected : bool ,
739
+ variable : & [ u8 ] ,
740
+ ) -> Option < predicates_core:: reflection:: Case < ' a > > {
741
+ self . 0 . find_case ( expected, variable)
742
+ }
743
+ }
744
+
745
+ impl < P > fmt:: Display for StrOutputPredicate < P >
746
+ where P : predicates_core:: Predicate < str >
747
+ {
748
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
749
+ self . 0 . fmt ( f)
750
+ }
751
+ }
752
+
753
+ impl < P > IntoOutputPredicate < StrOutputPredicate < P > > for P
754
+ where P : predicates_core:: Predicate < str >
755
+ {
756
+ type Predicate = StrOutputPredicate < P > ;
757
+
758
+ fn into_output ( self ) -> Self :: Predicate {
759
+ Self :: Predicate :: new ( self )
760
+ }
761
+ }
762
+
694
763
#[ cfg( test) ]
695
764
mod test {
696
765
use super :: * ;
0 commit comments