Skip to content

Random zero-copy fixes! #198

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

Merged
merged 3 commits into from
Aug 28, 2022
Merged

Conversation

Zij-IT
Copy link
Contributor

@Zij-IT Zij-IT commented Aug 27, 2022

While I was moving my lexer over to zero-copy there were some issues that I encountered related to TakeUntil, and I am sad to say it took like an hour and a half of dealing with Rusts wonderful generic errors before I was able to find the reason why.

The current implementation for of Parser is only implemented for TakeUntil<P, C>, and when one fills in the missing items, you get: TakeUntil<P, C, (), (), ()>. This was a particularly fun problem because C, which represents the collection that should be parsed into, is actually in the spot for the input generic I, which we can see when we look at the definition here pub struct TakeUntil<P, I: ?Sized, C = (), E = (), S = ()>

Additionally I fixed the bug that I accidentally introduced in one of my previous pull requests. At the time I believed it to be correct, and have gotten one less branch. What I didn't realize was that I removed the branch that assured that the offset index is within the &str. By removing that I enabled the classic "read memory that doesn't belong to you" bug.

Zij-IT added 3 commits August 27, 2022 19:45
1. `C` was written in place of `I` in the `TakeUntil<P, C>`
2. (Assuming 1 fixed) By not including the other trait bounds, it was only implemented for `TakeUntil<P, I, (), (), ()>`.
@zesterer
Copy link
Owner

Thanks! It's just occurred to me that there should probably be safe and unsafe variants of Input::next, given that it's a public trait.

@zesterer zesterer merged commit 7733322 into zesterer:zero-copy Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants