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

Provide a way to directly write newlines and comments #154

Closed
sdroege opened this issue May 11, 2020 · 2 comments
Closed

Provide a way to directly write newlines and comments #154

sdroege opened this issue May 11, 2020 · 2 comments

Comments

@sdroege
Copy link

sdroege commented May 11, 2020

Currently this is possible only by storing proc_macro2::Punct in a variable and interpolating that into a quote! { ... } block. It would be nice have a nicer way for this.

While functionally it doesn't make any difference, it could make the generated code more readable for debugging purposes and also allows to use quote as a general code generation mechanism outside of proc macros.

@dtolnay
Copy link
Owner

dtolnay commented May 11, 2020

I would prefer not to build this into quote, but there is room in the ecosystem for a different library geared toward this use case.

FWIW https://github.com/dtolnay/syn/blob/1.0.19/src/gen/fold.rs is produced using quote, including newlines and doc comments so it's possible to use as a general code generation mechanism outside of proc macros.

@dtolnay dtolnay closed this as completed May 11, 2020
@sdroege
Copy link
Author

sdroege commented May 11, 2020

Fair enough. That code you pasted there shows the exact problem though: densely packed without any empty lines between things, not readable at all :)

I'll continue to interpolate newlines into quote! { ... } blocks then for the meantime, it's not worth creating a new macro around quote just for this.

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

2 participants