Skip to content
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

Make "mem::replace to keep owned values in changed enums" example more general #38

Closed
briansmith opened this issue Oct 10, 2016 · 4 comments · Fixed by #45
Closed

Make "mem::replace to keep owned values in changed enums" example more general #38

briansmith opened this issue Oct 10, 2016 · 4 comments · Fixed by #45

Comments

@briansmith
Copy link

The example seems unrealistic because it uses if let instead of match. The example should use match since it is more general. Most of the cases where I would use this pattern would require the use of match.

@cbreeden
Copy link
Collaborator

Hmm, I tend to agree. The original PR used a match and then another PR simplified this particular example (and probably correctly so) to an if let. Perhaps it may be worthwhile to finding an example out in the wild unless someone else has another example in mind?

@diwic
Copy link
Contributor

diwic commented Oct 12, 2016

I use if let much more often than match.

@nrc
Copy link
Collaborator

nrc commented Oct 12, 2016

I don't we can say match or if let is more general or more common, but as a matter of style I think that example should use match - where you have where there is both an if let and an else branch, it is nearly always better to use match.

@briansmith
Copy link
Author

Maybe it's good to have two examples, one with if let and one with match. Then we can direct people to the specific example that most closely matches their code.

llogiq added a commit to llogiq/patterns that referenced this issue Dec 18, 2016
nrc pushed a commit that referenced this issue Jan 4, 2017
* Add another example to the mem::replace idiom

This fixes #38

* New anti-pattern: deny-warnings

* added deprecated link

* fix link title, add explanation why not deprecated

* incorporated hints from lfairy
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.

4 participants