4 releases

0.1.3 Apr 23, 2022
0.1.2 Dec 8, 2021
0.1.1 Dec 8, 2021
0.1.0 Dec 8, 2021

#36 in #concat

Download history 1294/week @ 2025-08-19 982/week @ 2025-08-26 1454/week @ 2025-09-02 2050/week @ 2025-09-09 1798/week @ 2025-09-16 1973/week @ 2025-09-23 1730/week @ 2025-09-30 1341/week @ 2025-10-07 1357/week @ 2025-10-14 1240/week @ 2025-10-21 592/week @ 2025-10-28 1241/week @ 2025-11-04 585/week @ 2025-11-11 1514/week @ 2025-11-18 811/week @ 2025-11-25 1407/week @ 2025-12-02

4,427 downloads per month
Used in 20 crates (7 directly)

MIT/Apache

12KB
229 lines

🚨 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");

Dependencies

~2MB
~47K SLoC