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 all parsers cloneable #41

Closed
tiziano88 opened this issue Jul 26, 2015 · 1 comment
Closed

Make all parsers cloneable #41

tiziano88 opened this issue Jul 26, 2015 · 1 comment

Comments

@tiziano88
Copy link

I'm quite new to Rust so excuse me if this makes no sense, but would it be possible to make all the combined parsers (e.g. Choice) implement the Clone trait?

@Marwes
Copy link
Owner

Marwes commented Jul 27, 2015

They should all implemented Clone though it appears I had forgotten to add it to Choice and AndThen so thanks for opening an issue!

Remember that the parsers requires that all inner parsers also needs to be cloneable (for them to implement Clone themselves) which is not always possible, usually because of satisfy(|c| ...) as closures do not implement clone. If you need to use a parser multiple time in a function you can wrap it in a closure and call it in every position it is needed instead.

let parser = my_long_parser;
(parser, ..., parser)

let parser = || my_long_parser;
(parser(), ..., parser())

(If you'd like I can push a new beta version to cargo though I will otherwise hold of until a larger/a few more changes comes through).

Fixed in 3a0cf4b

@Marwes Marwes closed this as completed Jul 27, 2015
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