Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to concat strings/bytes at compile time?

Tags:

constants

rust

Consider this example:

const TARGET_DIRECTORY: &'static str = "files";
const INDEX_FILE_PATH: &'static str = TARGET_DIRECTORY + "/index.txt"; // Should resolve to "files/index.txt"

This falters since the string on the left (TARGET_DIRECTORY) needs to be a String in order to use the + operator. One might try invoking TARGET_DIRECTORY.to_owned(), but that can't be executed at compilation.

like image 423
tigerros Avatar asked Dec 15 '25 06:12

tigerros


1 Answers

I found the constcat crate right after posting. There's other ones but this one is the simplest and smallest one. I'll mark this as an answer in 2 days.

like image 126
tigerros Avatar answered Dec 16 '25 22:12

tigerros



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!