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

accept FnMut instead of just Fn as take_till parameter #558

Open
2 tasks done
BLucky-gh opened this issue Jul 12, 2024 · 1 comment
Open
2 tasks done

accept FnMut instead of just Fn as take_till parameter #558

BLucky-gh opened this issue Jul 12, 2024 · 1 comment
Labels
A-combinator Area: combinators C-enhancement Category: Raise on the bar on expectations

Comments

@BLucky-gh
Copy link

Please complete the following tasks

winnow version

0.6.13

Describe your use case

I was trying to write a parser that runs take_till until it finds a matching bracket (keeping all the brackets found inside balanced), which requires a mutable counter variable to keep track of how many brackets have been found so far

Describe the solution you'd like

Allow passing FnMut to take_till to allow for more complex parsers without needing to make the entire parser stateful or juggling data in and out of a Cell

Alternatives, if applicable

I've used Cell and a move closure to keep the closure Fn while still allowing for mutating the counter, but I feel like it makes the closure unnecessarily complicated and long just to deal with juggling data in and out of the Cell, so I think if there's no functional reason to constraint the parameter to Fn, it should be relaxed

Additional Context

#552 (comment)

@BLucky-gh BLucky-gh added the C-enhancement Category: Raise on the bar on expectations label Jul 12, 2024
@epage
Copy link
Collaborator

epage commented Jul 13, 2024

By take_till, I'm assume you are referring to the impl ContainsToken<T> parameter that is used there and elsewhere.

That affects

  • one_of
  • none_of
  • take_till
  • take_while

This is an interesting one as I don't have a good feel for the trade offs of Fn vs FnMut with winnow.


For related conversations that might spark ideas:

For local context,

Looking back at nom's issues

@epage epage added the A-combinator Area: combinators label Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-combinator Area: combinators C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

2 participants