Closed g-plane closed 5 months ago
So you are wanting a Parser::with_state(self)
that, when parsing, returns (Output, State)
?
Could you expand on the use case for why capturing an owned State
during parsing is useful?
It doesn't need to capture an owned State
, but I need to read the state, for example, I use it in Parser::verify
to do some checks. I tried to let it return reference of State
, but I failed.
Sounds like this might be the same underlying need as #231 with a different proposal? Should we merge the discussions so we focus on the broader conversation on how to solve the need, regardless of the solution?
It can be merged.
Please complete the following tasks
winnow version
0.6.8
Describe your use case
Can we add a
with_state
method to theParser
trait when input isStateful
? (Simliar towith_span
)Describe the solution you'd like
Here is my current implementation in my code:
This can work in most cases. However, I prefer returning the reference of the state (which is
&input.state
) but I'm not able to achieve that.If we really can't return a reference, I hope the code above can be added to this library, so we can remove the
ParserExtForWithState
in our code.Alternatives, if applicable
No response
Additional Context
No response