Include_bytes! argument must be a string literal

It seems that include_bytes! only accepts string literals as arguments. Is there some alternative that would allow loading the contents of a file, whose location is specified at run-time, as bytes?

Did you mean "compile-time" here by any chance? If the file's location is only known at runtime, then you can't include it at compile time, of course. You would need to use something like std::fs::read() to read it into a Vec<u8>.

I really meant run-time. std::fs::read() is exactly what needed.

For a bit more context, the include_bytes!() macro is intended for embedding the contents of a file into your executable.

It's good for things like templates or static assets where you'd like the deploy process to be "just copy this executable around" without having to make sure a bunch of other files are in the right spot.


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.