X([[i16; 64]; 64]), [[i16; 64]; 64], [i16; 4096]

Can I do something to ensure that:

  • X([[i16; 64]; 64]),
  • [[i16; 64]; 64],
  • [i16; 4096]

have the same representation in memory and can be safely transmuted between each other ?

I want X(...) for the properties of type safety and abstraction. However, I also want it to share representation as [i16; 4096] for the benefits of memory mapping (a multi gigabyte file), which contains billions of X's.

This is already guaranteed for the latter two. To make the first one equivalent to those, you should add #[repr(transparent)] or #[repr(C)] on the declaration of the X struct.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.