| Crates.io | macropol |
| lib.rs | macropol |
| version | 0.1.4 |
| created_at | 2021-12-08 03:19:13.167987+00 |
| updated_at | 2026-01-23 17:22:24.257381+00 |
| description | Ergonomic string literal interpolation in macro definitions |
| homepage | |
| repository | https://github.com/yvt/macropol-rs |
| max_upload_size | |
| id | 494211 |
| size | 29,242 |
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 | Output | Notes |
|---|---|---|
"$foo" |
$foo |
$foo must expand to a string literal |
"$&foo" |
stringify!($foo) |
|
"${bar}" |
bar |
bar must expand to a string literal |
#[macropol::macropol]
macro_rules! mymacro {
($count:expr, $name:literal, fn $func:ident()) => {
/// Returns `"$$ $name, $&count to beam up"`.
fn $func() -> &'static str {
"$$ $name, ${stringify!($count)} 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!(3, "Scotty", fn func());
assert_eq!(func(), "$ Scotty, 3 to beam up");