Is there a way to do it? The concat macro only gives me static slices which I can't use a the format string for write.
Here's what I want to do: I have a struct I want to print out nicely (implementing Display), say each element on a new line. The format string would look like "Name: {}\n Project: {}", but I have a lot of elements. I guess I could write it down like
Any way to fix this? It would kinda feel comfortable to bind a literal to a variable, construct it in some more-or-less elaborate way and still use it correctly in a macro.
I feel like generating a custom formatter string using macros might be an X-Y problem. Can't you just use the debug_* methods on a std::fmt::Formatter to implement Display and only show the attributes you want?
Ah okay, I see what you are trying to do. You'd probably need to make your own custom formatter and then use that to write directly to the fmt::Formatter, although it's probably not worth the effort unless this is going to be something you use a lot.
Yeah I know how to do this basically, but I'm looking for a nice/convenient/elegant way to construct the format string, which needs to be a string literal and therefore not accessible via the methods one can use on a string.
That final slash for a multiline string to also ignore the leading whitespaces pretty much does it for me, so... success!