macropol

Crates.iomacropol
lib.rsmacropol
version0.1.3
sourcesrc
created_at2021-12-08 03:19:13.167987
updated_at2022-04-23 05:53:56.390354
descriptionErgonomic string literal interpolation in macro definitions
homepage
repositoryhttps://github.com/yvt/macropol-rs
max_upload_size
id494211
size26,526
yvt (yvt)

documentation

README

🚨 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!.

#[macropol::macropol]
macro_rules! mymacro {
    ($count:expr, $name:expr, fn $func:ident()) => {
        /// Returns `"$$ $name, ${stringify!($count)} to beam up"`.
        fn $func() -> &'static str {
            "$$ $name, $&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");
Commit count: 10

cargo fmt