File tree 3 files changed +52
-0
lines changed
3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 11
11
pub use core:: Predicate ;
12
12
pub use boolean:: PredicateBooleanExt ;
13
13
pub use boxed:: PredicateBoxExt ;
14
+ pub use str:: PredicateStrExt ;
14
15
15
16
/// Predicate factories
16
17
pub mod predicate {
Original file line number Diff line number Diff line change
1
+ use Predicate ;
2
+
3
+ /// Predicate adaper that trims the variable being tested.
4
+ ///
5
+ /// This is created by `pred.trim()`.
6
+ #[ derive( Copy , Clone , Debug ) ]
7
+ pub struct TrimPedicate < P >
8
+ where
9
+ P : Predicate < str > ,
10
+ {
11
+ p : P ,
12
+ }
13
+
14
+ impl < P > Predicate < str > for TrimPedicate < P >
15
+ where
16
+ P : Predicate < str > ,
17
+ {
18
+ fn eval ( & self , variable : & str ) -> bool {
19
+ self . p . eval ( variable. trim ( ) )
20
+ }
21
+ }
22
+
23
+ /// `Predicate` extension adapting a `str` Predicate.
24
+ pub trait PredicateStrExt
25
+ where
26
+ Self : Predicate < str > ,
27
+ Self : Sized ,
28
+ {
29
+ /// Returns a `TrimPedicate` that ensures the data passed to `Self` is trimmed.
30
+ ///
31
+ /// # Examples
32
+ ///
33
+ /// ```
34
+ /// use predicates::prelude::*;
35
+ ///
36
+ /// let predicate_fn = predicate::str::is_empty().trim();
37
+ /// assert_eq!(true, predicate_fn.eval(" "));
38
+ /// assert_eq!(false, predicate_fn.eval(" Hello "));
39
+ /// ```
40
+ fn trim ( self ) -> TrimPedicate < Self > {
41
+ TrimPedicate { p : self }
42
+ }
43
+ }
44
+
45
+ impl < P > PredicateStrExt for P
46
+ where
47
+ P : Predicate < str > ,
48
+ {
49
+ }
Original file line number Diff line number Diff line change 12
12
13
13
mod basics;
14
14
pub use self :: basics:: * ;
15
+ mod adapters;
16
+ pub use self :: adapters:: * ;
15
17
16
18
#[ cfg( feature = "difference" ) ]
17
19
mod difference;
You can’t perform that action at this time.
0 commit comments