Ideas for API improvements #392
Replies: 4 comments 3 replies
-
|
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
This requires a blanket |
Beta Was this translation helpful? Give feedback.
-
This was initially reported against nom in rust-bakery/nom#1586 and then fixed in -bakery/nom#1587, after we forked. I didn't initially fix it or copy over the fix due to lack of experience with For example, |
Beta Was this translation helpful? Give feedback.
-
I found a few instances where the winnow API could be nicer and instead of being slightly annoyed about it not being that, I thought I would rather document them here and see what other people think about these ideas.
ParserIterator
should implement iterator onSelf
instead of&'a mut Self
:This point is pretty important for me as it makes the API just nicer
and has no apparent drawbacks.
Especially because
Iterator
should almost always be implemented onSelf
,because the standard library already contains
impl<T: Iterator> Iterator for &mut T
,making an impl on
&mut Self
kind of redunant.Iterator
,Parser
should have animpl<T: Parser> Parser for &mut Parser
-impl as well.This can be useful when having a parser that contains some inner parser
and enables just using the normal chaining functions on
&mut inner_parser
instead of needing to use.parse_next()
manually.Note that both changes might require major version bump,
though I'm not sure because of
1.
the same impl should then be covered by theimpl<T: Iterator> Iterator for &mut T
of iterator(though theoretically someone could depend on
&mut &mut ParserIterator
implementingIterator
.)and for
2.
it should not conflict with any existing code, but still might.I will add to this list if I find more things, which could be improved.
Beta Was this translation helpful? Give feedback.
All reactions