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

quote-compatible example #61

Open
rambip opened this issue Sep 23, 2023 · 1 comment
Open

quote-compatible example #61

rambip opened this issue Sep 23, 2023 · 1 comment

Comments

@rambip
Copy link

rambip commented Sep 23, 2023

I think it would be very valuable to have an example in the root documentation showing how to use with the quote crate.

Something like this:

fn main() {
    let rust_snippet = quote!{
        fn hello_world() {println!("hello world !")}
    };

    let abstract_file : File = syn::parse2(rust_snippet);
    let pretty_rust = prettyplease::unparse(abstract_file);

    println!(pretty_rust);
}
@inferiorhumanorgans
Copy link

This seems to be a really common theme (without an explicitly spelled out answer) for prettyplease issues. In short the answer is to manually construct a File object and use syn::parse2 to convert the TokenStream into Items that File wants.

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