implementation of Predicate
is not general enough
#370
-
Hey, I can't get this to compile
(see #61 for an explanation why the lifetime specification And use it:
Any hints on how I can convince the compiler to do what I want? Using a My workaround to achieve the same in the test:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The problem is that you need a Predicate that matches the same lifetime as the function's argument, but that's hard. An easy workaround is to use m.expect_foo().withf(|value| value == None); which can probably be more efficiently written as m.expect_foo().withf(Option::is_none); |
Beta Was this translation helpful? Give feedback.
The problem is that you need a Predicate that matches the same lifetime as the function's argument, but that's hard. An easy workaround is to use
withf
instead ofwith
. Though it looks like shorthand forwith(predicates::Func)
, it actually has more relaxed lifetime requirements.which can probably be more efficiently written as