dtolnay / quote

Rust quasi-quoting
Apache License 2.0
1.32k stars 90 forks source link

Add special syntax for using strings as identifiers #284

Closed nyurik closed 1 month ago

nyurik commented 1 month ago

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 commented 1 month ago

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.