Skip to content

Implement Clone for possible matchers #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kupiakos opened this issue Feb 1, 2024 · 3 comments · Fixed by #356
Closed

Implement Clone for possible matchers #355

kupiakos opened this issue Feb 1, 2024 · 3 comments · Fixed by #356

Comments

@kupiakos
Copy link

kupiakos commented Feb 1, 2024

To simply reuse the same long matcher expression across multiple checks.

@bjacotg
Copy link
Collaborator

bjacotg commented Feb 1, 2024

What about injecting an & before the matcher in verify_that!, assert_that! and expect_that!, like it is done for actual?

This would solve the problem for:

let actual = 2;
let matcher = eq(2);
assert_that!(actual, matcher);
assert_that!(actual, matcher); // both pass by ref so ok!

It wouldn't solve the issue for:

let matcher = eq(2);
assert_that!(vec![2, 2], [matcher.clone(), matcher]);

which will require implementing Clone for matchers.

The first one is fairly simple to implement right now. The second is no more complicated, but I will need to make all matcher function return concrete types as part of #323 fix, so I may save this for later.

WDYT?

@bjacotg
Copy link
Collaborator

bjacotg commented Feb 2, 2024

I run into temporary lifetime issue by taking the matcher by reference. However, in #356, I just made all &impl Matcher implement Matcher which seems to fix both issues.

@kupiakos
Copy link
Author

kupiakos commented Feb 5, 2024

@bjacotg Implementing Clone might still be useful for other reasons, but matching on &Matcher works just as well for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants