I'd like to propose a new modifier for variable conversion named unquote. When applied to a string literal variable, it should remove the quotes, producing tokens.
Example:
fn foo() {}
macro_rules! bar {
($literal:literal) => {
paste!([<$literal:unquote>]());
};
}
bar!("foo"); // - expands to foo().
Use case:
I have a macro_rules derive macro, implemented using https://crates.io/crates/macro_rules_attribute. User input is expected to contain an attribute, #[foo(some_attr = "path::to::func")]. Since it is impossible to specify paths in Rust meta, a common pattern is to ask users to provide a string literal instead, the proc macro then parses it as expected token type. One example of a crate that uses this pattern is serde: https://serde.rs/container-attrs.html#default--path.
Since the purpose of paste is to enable macro_rules to do what normally only proc macros can do, I think this would be a nice addition.
I'd like to propose a new modifier for variable conversion named
unquote
. When applied to a string literal variable, it should remove the quotes, producing tokens.Example:
Use case:
I have a macro_rules derive macro, implemented using https://crates.io/crates/macro_rules_attribute. User input is expected to contain an attribute,
#[foo(some_attr = "path::to::func")]
. Since it is impossible to specify paths in Rust meta, a common pattern is to ask users to provide a string literal instead, the proc macro then parses it as expected token type. One example of a crate that uses this pattern is serde: https://serde.rs/container-attrs.html#default--path.Since the purpose of
paste
is to enable macro_rules to do what normally only proc macros can do, I think this would be a nice addition.