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

Consider adding type for partial parsing #835

Closed
Kestrer opened this issue May 28, 2020 · 2 comments
Closed

Consider adding type for partial parsing #835

Kestrer opened this issue May 28, 2020 · 2 comments

Comments

@Kestrer
Copy link

Kestrer commented May 28, 2020

Sometimes I need to parse one item, and then keep the rest of the tokens for later. I would like a struct in syn::parse:

pub struct ParseStart<T: Parse> {
    pub item: T,
    pub rest: TokenStream,
}

I'm not certain about the name, it could also be called PartialParse or ParseOne, and there is also the question of whether to have a separate ParseStart and ParseStart2 for proc_macro::TokenStream and proc_macro2::TokenStream respectively. We could even blanket impl Parse for (T, U) for maximum flexibility and minimum API surface.

Previous discussion has happened here and here but this is a slightly different approach.

If you think this is a good idea and can answer my above questions I'm happy to go ahead and make a PR.

@dtolnay
Copy link
Owner

dtolnay commented May 28, 2020

I think I would prefer not to build this into Syn. But if there is an abstraction along these lines that is reasonably widely used in downstream crates, I would be interested to know (with links).

@dtolnay dtolnay closed this as completed May 28, 2020
@tqwewe
Copy link

tqwewe commented Apr 4, 2022

Is this still not possible currently? It would be very useful in my case, and I'm not sure what the alternatives approaches are

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

No branches or pull requests

3 participants