#string-literal #string #macro #proc-macro #literals #compile-time #replace

nightly macro string-literal-const-replace

Proc macro for compile-time find/replace on string literals

1 unstable release

new 0.1.0 Feb 12, 2025

#1451 in Rust patterns

Download history 108/week @ 2025-02-11

108 downloads per month

MIT/Apache

8KB
72 lines

string-literal-const-replace

This is a proc macro which allows you to, at compile time, perform find/replace on string literals. This macro is intended to be called by other macros, to do processing on inputs provided to the macro.

Note that this macro is nightly-only as it relies on the proc_macro_expand unstable feature.

Example of use:

assert_eq!(
    string_literal_replace!("hello, world!" ("hello" -> "goodbye")),
    "goodbye, world!"
);

lib.rs:

A macro for compile-time replacement on string literals.

This is meant for combining with other macros, such as doing a find/replace on a stringify! result in a const context.

See string_literal_replace!.

Dependencies

~205–640KB
~15K SLoC