Skip to content

ParseElem missing lifetime specifiers #268

Closed
@zsol

Description

@zsol
Contributor

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?

Activity

kevinmehall

kevinmehall commented on Aug 29, 2021

@kevinmehall
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

kevinmehall commented on Jan 2, 2022

@kevinmehall
Owner

Fixed by f09fc34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @zsol@kevinmehall

      Issue actions

        ParseElem missing lifetime specifiers · Issue #268 · kevinmehall/rust-peg