#replace #macro #proc-macro #compile-time #string #procedural #file

macro rimpiazza

A compile time procedural macro to replace keywords in a string

3 unstable releases

0.2.0 Aug 1, 2023
0.1.1 Jul 31, 2023
0.1.0 Jul 31, 2023

#2012 in Procedural macros

GPL-3.0 license

15KB
78 lines

Rimpiazza

The simple procedural macro to replace keywords from a string.

Example

Standard replacing:

println!(
    "{}",
    replace!("I like Gelato", "Gelato" => "ice cream, a lot!", "like" => "hate")
);

Replace contents from a file:

println!(
    "{}",
    replace!(:"./gelato.txt", "Gelato" => "ice cream, a lot!", "like" => "hate")
    // Notice the : character
);

That's it, it does not have any more fancy features.

Use cases

I created this because Internet Explorer 11 has no support for css variables, with this macro, I can add them to my css from my rust backend. Previously I just used a function, but this is much more fast as it is compile-time.

Is this still being worked on?

This is such a simple thing it does not need much support.
If I find a bug I will fix it, but it's a very small macro and does not need a lot of development.

Dependencies

~290–740KB
~18K SLoC