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

ParseElem missing lifetime specifiers #268

Closed
zsol opened this issue Aug 29, 2021 · 2 comments
Closed

ParseElem missing lifetime specifiers #268

zsol opened this issue Aug 29, 2021 · 2 comments

Comments

@zsol
Copy link
Contributor

zsol commented Aug 29, 2021

I'd like to write a ParseElem implementation that returns references to the original input - something like:

impl ParseElem<'input> for Vec<Token> {
  type Element = &'input Token;
  fn parse_elem(&'input self, pos: usize) -> RuleResult<Self::Element> {
    match self.get(pos) {
      Some(tok) => RuleResult::Matched(pos + 1, tok),
      None => RuleResult::Failed,
    }
  }
}

But unfortunately with the current ParseElem definition I don't think this is possible. Is there any reason ParseElem doesn't have an explicit lifetime specifier (like ParseSlice does)? And if not, would you accept a PR to implement it?

@kevinmehall
Copy link
Owner

That seems fine. I don't think there's a reason it was omitted besides that the str and [T] impls didn't need it because they clone the elements.

I'd accept a PR. It is a breaking change, but it can go in 0.8.

@kevinmehall
Copy link
Owner

Fixed by f09fc34

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 a pull request may close this issue.

2 participants