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

fold's param init func should be FnOnce instead of FnMut #1742

Closed
sify21 opened this issue Apr 24, 2024 · 2 comments
Closed

fold's param init func should be FnOnce instead of FnMut #1742

sify21 opened this issue Apr 24, 2024 · 2 comments

Comments

@sify21
Copy link

sify21 commented Apr 24, 2024

Take this for example

move || init,

You can't move the captured variable init out of the "init" func if it is a non-Copy type, even though init variable has been moved into the capturing "init" func. That's because FnMut means "init" can be called multiple times. This only works as a matter of fact that init variable is i64 in this case.

Since this func is called only once, FnOnce is more suitable here.

@Geal
Copy link
Collaborator

Geal commented May 5, 2024

with the way the Parser trait is designed, it cannot be a FnOnce, because there's no guarantee that the parser would be called only once: you can take the result of fold and call parse on it with various inputs

@sify21
Copy link
Author

sify21 commented May 11, 2024

Got it! A Parser is reusable

@sify21 sify21 closed this as completed May 11, 2024
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

No branches or pull requests

2 participants