This is what I'm trying to do:
fn foo() -> &'static str {
let x = "Jeff";
return &format!("Hello, {}", x);
}
I understand that it's not possible, since format!() makes a String in heap, while the result of foo is expected to be in static memory. Is there a similar macro/function, which would work like this:
fn foo() -> &'static str {
let x = "Jeff";
return static_format!("Hello, {...}", x);
}
Here, {...} is a five-bytes placeholder for world. The macro static_format! should allocate Hello, {...} in static, fill it up with arguments, and return it. Or maybe something else is possible, to simplify the process of formatting-and-returning static strings?