winnow-rs / winnow

Making parsing a breeze
https://docs.rs/winnow
Other
573 stars 46 forks source link

Use references for `&[T]`s token type #590

Open yyy33 opened 2 months ago

yyy33 commented 2 months ago

Let users decide if they want to clone or not when they use it

where an &T is returned instead of a T: code

epage commented 2 months ago

Are you meaning to change type Token = T; to type Token = &T;?

If we did then that would first be a breaking change and require waiting until we feel its appropriate to make one.

Also, that signature I gave is incomplete. We'd need that to be type Token<'t> = &'t T. I've not dealt much with GATs, I'm unsure if we can do type Token<'static> = char in other cases. &str streams with a token of char is an example of where we can't use a reference.

It'd be good to experiment with this to see how feasible it is to do something like this before we get to 0.7

yyy33 commented 2 months ago

Are you meaning to change type Token = T; to type Token = &T;?

yes

epage commented 2 months ago

Also started #591 to discuss this and other needs.