🚨 macropol
Ergonomic string literal interpolation in macro definitions.
Replaces metavariables ($foo) and arbitrary expressions in string literals (including doc comments) and concatenates them with surrounding text fragments with core::concat!.
Syntax Overview
| Syntax | Output | Notes |
|---|---|---|
"$foo" |
$foo |
$foo must expand to a string literal |
"$&foo" |
stringify!($foo) |
|
"${bar}" |
bar |
bar must expand to a string literal |
Example
to beam up"
}
};
}
// The above definition expands to:
//
// macro_rules! mymacro {
// ($count:expr, $name:expr, fn $func:ident()) => {
// #[doc = concat!("Returns `\"$ ", $name, ", ",
// stringify!($count), " to beam up\"`.")]
// fn func() -> &'static str {
// concat!("$ ", $name, ", ",
// stringify!($count), " to beam up")
// }
// };
// }
//
mymacro!;
assert_eq!;