The format! macro needs to know the actual format string at compile time. This excludes using variable and statics, but also consts (which are known at compile time, but at a later compilation phase than macro expansion).
However in this specific case you can solve your problem by emulating a variable with another macro:
The
format!
macro needs to know the actual format string at compile time. This excludes using variable andstatic
s, but alsoconst
s (which are known at compile time, but at a later compilation phase than macro expansion).However in this specific case you can solve your problem by emulating a variable with another macro:
(Permalink to the playground)
If your format string isn't actually know at compile and can't be used in a macro like this, then you need to use a dynamic template engine.