I have a simple template like "hello {blank} how are you?"
and 2 separate functions that need to hard code "blank" with static values (can be known at compile time).
I don't want to hard code this templated text to the functions.
I'm looking for something like a C
#DEFINE
macro which will just "stick" the value into the string.
Contrived:
// my macro/ const function or what ever needs to be here:
const fn / macro! fill_text(name: &str) -> {return format!("hello {name} how are you") } // at compile time should be evaluated, not at run time
fn say_hello_to_john() ->&'static str {
fill_text("john")
}
fn say_hello_to_jane() -> &'static str {
fill_text("jane")
}
Tried this but it doesn't yield a static string:
macro_rules! fill_text {
$text:expr => {
format!("hello {} how are you", $text) // how to make this static?
}
}