Skip to content

implementation of Predicate is not general enough #370

Answered by asomers
marvinthepa asked this question in Questions
Discussion options

You must be logged in to vote

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 of with. Though it looks like shorthand for with(predicates::Func), it actually has more relaxed lifetime requirements.

m.expect_foo().withf(|value| value == None);

which can probably be more efficiently written as

m.expect_foo().withf(Option::is_none);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by marvinthepa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants