2

For a programming language VM I have been working on lately I need to create a stack for data. I have decided to use a Vec<u8> and then convert data to slices of u8.

Although turning strings into u8 is trivially easy, turning f32s and i32s into u8 slices is less obvious. If this were C I would just do a cast; however, that doesn't seem to work in Rust.

What is the best way to convert these types into slices of u8?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • 2
    https://doc.rust-lang.org/std/primitive.f32.html#method.to_bits; https://doc.rust-lang.org/std/primitive.u32.html#method.to_le_bytes – Shepmaster Mar 30 '21 at 02:05

0 Answers0