-
Notifications
You must be signed in to change notification settings - Fork 52
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
map
with both Output and Stream
#231
Comments
@epage feel free to rename the issue to something better, I was struggling to find a good title. |
map
-like fashionmap
with both Output and Stream
I was thinking about it a bit more and checked the existing API of the
Then you could simply access this via a I can try to compile a draft PR for this approach in the next few days and play around with it a bit to see if this would actually work in the way I envision. |
I'm also not too nailed down on the naming yet. Maybe |
This is a draft implementation to solve winnow-rs#231
Another name for this could be |
chumsky consolidated a of their various I don't think we should do that for the common cases but it provides a general form for complex cases. The main difference with the proposal here is we'd want to also include |
I wonder if we could use "tacit trait specialization", like axum and bevy, to allow a broad selection of function signatures to all work with one combinator. |
Do you envision something like I'm a little bit torn about this because on one hand it improves flexibility, but on the other hand it'll make it harder to reason about what certain APIs expect from the user. I'm always a bit scared of APIs that involve a lot of generic type parameters -- especially when these are imposed by one or more traits -- because it sometimes makes it really hard to understand which input types satisfy the contract and which don't. I'd probably take the stance of having more methods that are less generic but serve a distinct purpose rather than cramming too much into a single API. |
Please complete the following tasks
winnow version
v0.4.1
Describe your use case
See the discussion thread #230 (comment)
The general idea is to get access to the state of a
winnow::stream::Stateful
input in amap
-like function so that it can be updated while mapping a parser's output.Right now, only simple use cases are supported, like the one shown in the
Stateful
type docs.Describe the solution you'd like
A method on the
Parser
trait that allows to modify the state in amap
-like operation.Ideally something like
map_with_state
that would both provide the output of the previous parser, and a reference to thestate
inside theStateful
so that it could be updated.There was another idea in #230 (comment) to generalize this to not only support the
Stateful
input type, but any input type by having something likemap_with_input
to expose a reference to the whole input, not just thestate
in aStateful
.Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: