Skip to content
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

Added support for [u8] inputs in Location #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

danielparks
Copy link

This fixes a problem where using final_parser() on a byte string ([u8]) input would fail to compile because Location did not know how to handle anything other than str.

I tried to keep this as small and simple as possible. An alternative fix would have been to adjust Location::locate_tail() to take generic parameters that could handle both [u8] and str, but that would be significantly more complicated and harder to understand.


I’m happy to change things around however you want.

This fixes a problem where using `final_parser()` on a byte string
(`[u8]`) input would fail to compile because `Location` did not know how
to handle anything other than `str`.

I tried to keep this as small and simple as possible. An alternative fix
would have been to adjust `Location::locate_tail()` to take generic
parameters that could handle both `[u8]` and `str`, but that would be
significantly more complicated and harder to understand.
@Lucretiel
Copy link
Owner

Thanks for the contribution! I wasn't sure that raw bytes would usually constitute something human readable, for which line and column offsets would make sense, but I was probably being a little bit too picky.

If you could simplify it to resemble something like this:

pub fn locate_tail<'a>(original_input: &'a [u8], tail: &'a [u8]) -> Self { 
    // The original locate_tail function
}

impl RecreateContext<&[u8]> for Location {
    fn recreate_context(original_input: &[u8], tail: &[u8]) -> Self {
        Location::locate_tail original_input, tail)
    }
}

impl RecreateContext<&str> for Location {
    fn recreate_context(original_input: &str, tail: &str) -> Self {
        Location::locate_tail_bytes(original_input.as_bytes(), tail.as_bytes())
    }
}

Then I'm happy to merge

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