I'm trying to load a folder of animation frames at compile time. The frames are named like this: frame1.png, frame2.png, ... frameN.png. Unfortunately after trying multiple methods for a while, I have come to the conclusion that this might not be possible. Am I correct?
Essentially the final data should look like this:
static DATA: &[&[u8]] &[
[frame1 bytes],
[frame2 bytes],
...
[frameN bytes],
];
Here's what I've been trying to do:
macro_rules! import_img_anim {
($name:ident, $path:expr, $n:literal) => {
static $name: &[&[u8]] = &[
seq_macro::seq!(N in 1..=$n {
include_bytes!(concat!($path, "/frame", stringify!(N), ".png")),
})
];
};
}
But the compiler gives this cryptic error message at include_bytes!:
"macro expansion ignores token include_bytes and any following
the usage of seq_macro::seq! is likely invalid in expression context"
Surely there's a way to do this? Rust's macros are widely regarded as immensely powerful, yet I can't even write a for loop in a comp-time context... (at least without including exernal crate)
include_bytes!creates a sized array of bytes. So if you have a fixed frame size, you will have to specify it: play.rust-lang.org/…[]inside theseq!macro.