-
Notifications
You must be signed in to change notification settings - Fork 794
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
Parser associated types #1626
Parser associated types #1626
Conversation
this reduces the number of generic types in some combinators, which will be useful when I reintroduce some complexity there later
The output type should now mainly come from assocated types instead of being an explicit generic type. From a few tests here and there, it appears that the error type could be removed too
f: F, | ||
g: G, | ||
phantom: core::marker::PhantomData<O1>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that this lets you drop the phantom data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it simplifies them nicely. I have to check again the methods like flat_map
, to make sure that they require all the trait bounds, otherwise it would be possible for them to return a value that does not implement Parser
, which would be confusing
Any hint if this improved type inference at all? Or any other benefit noticed besides dropping the number of generic parameters / phantom data? |
Pull Request Test Coverage Report for Build 3976558656Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
so far the main issue with type inference was that I had to add the error type explicitely ( |
Just gave this a try in winnow-rs/winnow#220 and it looks like the compiler isn't happy about implementing impl<I, E> Parser<I> for u8
where
I: StreamIsPartial,
I: Stream<Token = u8>,
E: ParseError<I>,
{
type Output = u8;
type Error = E;
fn parse_next(&mut self, i: I) -> IResult<I, u8, E> {
crate::bytes::one_of(*self).parse_next(i)
}
}
This would require hard coding the error type which would be unpleasant to then make it seemless with other parts of the API. I guess only |
I found doubling down on |
No description provided.