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

Add special syntax for using strings as identifiers #284

Closed
nyurik opened this issue Sep 16, 2024 · 1 comment
Closed

Add special syntax for using strings as identifiers #284

nyurik opened this issue Sep 16, 2024 · 1 comment

Comments

@nyurik
Copy link

nyurik commented Sep 16, 2024

Far too often I find myself having a String with the needed identifier:

fn construct_foo_call(type_name: &str) -> TokenStream {
    let ident = format_ident!("{type_name}");
    quote! {
        foo(#ident);
    }
}

Is there a way quote! can support direct usage of strings as identifiers, e.g.

fn construct_foo_call(type_name: &str) -> TokenStream {
    quote! {
        foo(##type_name);
    }
}

or

fn construct_foo_call(type_name: &str) -> TokenStream {
    quote! {
        foo(@type_name);
    }
}
@dtolnay
Copy link
Owner

dtolnay commented Sep 16, 2024

I would prefer not to add new special syntax in this crate for this operation. But, you're free to make your own quasiquoting macro crate that is more fully featured.

@dtolnay dtolnay closed this as completed Sep 16, 2024
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