Here's some sample syntax:
let myResourceBytes = #embed("myResource")
Following random links, I found a C++ proposal to create an object that is a byte dump of a specified file. It's supposed to replace hacks that read the file and insert it into a *.cpp (or *.hpp) file as a large array literal.
- The latest link to the proposal
- Some snarky discussions about it
- Similar feature in Rust
- Similar feature in D
- Similar feature in Nim
The argument to #embed
is a compile-time string. The format of what's in the string to what file, URL, or other resource to read for the data is implementation-specified. I'm wondering what the return type should be. It could be:
- A standard library
Array
:[UInt8]
- A fixed-sized array:
[XXX ; UInt8]
, where XXX is the byte length of the resource
If we go with the latter, then the embedding feature is blocked until FSAs are done. The C++ author wanted to use their embed command in constexpr
contexts, where the compiler can trim out unused portions of what would go into the binary. If we can do compile-time manipulations on a standard-library Array
, then we could add this feature earlier.
I remember trying out things like:
let tooShort: Int8 = 500
And although the default integer types are part of the standard library, the compiler still pierced the expression and reported the literal is too large for the type. Can we do similar manipulations with Array
? If not, could it be added? Could it be added in a way cheaper than the FSA route?