What is the best way to use include_bytes! and give the resulting binary blob a specific alignment? For example if the blob contains a bunch of C structs, or any other number of reasons.
Is there a more clean way to achieve what I've done with this hack, beyond just hiding it with a macro?
#[repr(align(4))]
struct Wrapper([u8; include_bytes!("file").len()]);
const MY_DATA: &[u8] = &Wrapper(*include_bytes!("file")).0;
I'd imagine the double include_bytes! is not great for build times either...
1 Like
Ah, that would work indeed! Thank you
1 Like
vmedea
March 6, 2020, 4:02pm
4
Yes AFAIK there still is no cleaner way than that, at least it avoids the double include_bytes
.
1 Like
ExpHP
March 6, 2020, 6:09pm
5
I've added a macro to the prior linked comment which encapsulates the construction of the static to keep things even cleaner.
(I still don't think it's big enough to be worth publishing and maintaining a crate for it, though!)
Edit: Actually, now that I'm thinking about it, maybe it's worth having a crate for, just for discoverability.
2 Likes
vmedea
March 6, 2020, 9:16pm
6
Thanks, just switched to that, that's perfect!
1 Like
system
Closed
June 4, 2020, 9:16pm
7
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.