rust-peg icon indicating copy to clipboard operation
rust-peg copied to clipboard

Stop implicitly adding `&'input` to input type

Open kevinmehall opened this issue 2 years ago • 0 comments

Rust-peg currently adds &'input to the specified input type. The 'input lifetime violates macro hygiene and is confusing to use along with other explicitly-declared lifetimes used in the input type.

This change also allows Copy input wrapper types like SliceByRef to be zero-cost, instead of adding another layer of pointer indirection.

Breaking change

All grammars must add & to their input type, and if they use the 'input lifetime, must explicitly declare it.

Before:

grammar g() for str {

After:

grammar g() for &str {

or

grammar g<'input>() for &'input str {

Additionally, the signatures of the Parse, ParseElem, ParseLiteral, and ParseSlice traits have changed. If you implement these traits for custom input types, you'll need to make changes to implement these traits for &T rather than T, and take self rather than &self.

To Do

  • [ ] Detect unfixed str and [T] input types and either automatically do the right thing or give an error message that is more actionable than the one Rust gives.

kevinmehall avatar May 15 '22 15:05 kevinmehall