I'm using a library for string interning (string-cache), that uses macros to efficient create elements (atom!
). However for simplification here is a similar macro that demonstrates the problem
macro_rules! string_intern {
("d") => ("Found D");
}
say I need to call this macro from another macro and give it a string version of an identifier.
macro_rules! print_ident {
($id:ident) => (
string_intern!(stringify!($id));
);
}
However calling this macro
fn main() {
print_ident!(d);
}
Fails with error:
error: no rules expected the token `stringify`
--> <anon>:7:24
|
7 | string_intern!(stringify!($id));
| ^^^^^^^^^
I know stringify!
correctly converts to identifier d
to string "d"
, because giving it to println!
works as expected. Is there a way to pass the identifier I want turned into string to string_intern
?