0

I wanted to embed an image to my binary and used the "include_bytes" macro. The GUI library I wanted to use only accepts [u32] for input and the said macro produces only [u8].

How do I convert a [u8] to a [u32]? I've seen some in the internet but the explanations are a bit too technical for me (I'm only self-taught). There were several options that I saw like bitwise and a method in "u32" from the standard library. Anyone can give an actual code on how to do it? Like study it from there in case I will need it for other files in the future. Thank you. I almost always just understand things via code coz I'm not aware of many technical terms, algos, etc.

amviel
  • 1
  • 1

1 Answers1

1

using .map(Into::<u32>::into)

fn main() {
    assert_eq!([0_u8, 1_u8].map(Into::<u32>::into), [0_u32, 1_u32]);
}
Sprite
  • 3,222
  • 1
  • 12
  • 29
  • 2
    It will mostly depends on the representation. Not sayin this is wrong though. But if you have byes, maybe the `u32` is the actual first 4 bytes (`u8`), the second one the next 4 and so on. – Netwave Feb 02 '22 at 15:06