How to combine two string literals at compile time?

I'd like to have a null-terminated string literal of a path in windows, which has a lot of backslashes.
I don't want to escape all those backslashes, and I'd rather use a raw string (r""). But now null termination ("\0") will also be inserted as a string, not as a null-byte.

Is there a way in rust to combine two strings (one raw, and one regular)?
The C++ syntax (simply placing two strings adjacent to each other) didn't work:

let s = r"C:\Program Files\MyApp" "\0";

Is there another way?

I think const_format::concatcp should allow you to combine both strings at compile time like this:

use const_format::concatcp;

const S: &str = concatcp!(r"C:\Program Files\MyApp", "\0");
1 Like

I believe the concat! macro should do what you want.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.