File tree 1 file changed +12
-0
lines changed 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ use Predicate;
19
19
pub struct FnPredicate < F , T >
20
20
where
21
21
F : Fn ( & T ) -> bool ,
22
+ T : ?Sized ,
22
23
{
23
24
function : F ,
24
25
name : & ' static str ,
28
29
impl < F , T > FnPredicate < F , T >
29
30
where
30
31
F : Fn ( & T ) -> bool ,
32
+ T : ?Sized ,
31
33
{
32
34
/// Provide a descriptive name for this function.
33
35
///
54
56
impl < F , T > Predicate < T > for FnPredicate < F , T >
55
57
where
56
58
F : Fn ( & T ) -> bool ,
59
+ T : ?Sized ,
57
60
{
58
61
fn eval ( & self , variable : & T ) -> bool {
59
62
( self . function ) ( variable)
63
66
impl < F , T > fmt:: Display for FnPredicate < F , T >
64
67
where
65
68
F : Fn ( & T ) -> bool ,
69
+ T : ?Sized ,
66
70
{
67
71
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
68
72
write ! ( f, "{}(var)" , self . name)
@@ -94,10 +98,18 @@ where
94
98
pub fn function < F , T > ( function : F ) -> FnPredicate < F , T >
95
99
where
96
100
F : Fn ( & T ) -> bool ,
101
+ T : ?Sized ,
97
102
{
98
103
FnPredicate {
99
104
function,
100
105
name : "fn" ,
101
106
_phantom : PhantomData ,
102
107
}
103
108
}
109
+
110
+ #[ test]
111
+ fn str_function ( ) {
112
+ let f = function ( |x : & str | x == "hello" ) ;
113
+ assert ! ( f. eval( & "hello" ) ) ;
114
+ assert ! ( !f. eval( & "goodbye" ) ) ;
115
+ }
You can’t perform that action at this time.
0 commit comments