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
Download history 102/week @ 2023-07-18 49/week @ 2023-07-25 22/week @ 2023-08-01 40/week @ 2023-08-08 62/week @ 2023-08-15 29/week @ 2023-08-22 28/week @ 2023-08-29 90/week @ 2023-09-05 70/week @ 2023-09-12 33/week @ 2023-09-19 42/week @ 2023-09-26 50/week @ 2023-10-03 124/week @ 2023-10-10 111/week @ 2023-10-17 69/week @ 2023-10-24 110/week @ 2023-10-31

424 downloads per month
Used in 10 crates (5 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

~1.5MB
~37K SLoC