aligned icon indicating copy to clipboard operation
aligned copied to clipboard

Representation guarantee?

Open Rua opened this issue 1 year ago • 1 comments
trafficstars

Is there a guarantee that Aligned<A, T> has the same memory representation as T, and is thus sound to transmute to T?

Rua avatar Jun 16 '24 07:06 Rua

My understanding is:

  • The alignment struct is repr(C)
  • ZSTs are ignored when a struct is repr(C)
  • Alignment is ensured via a ZST array.
  • The layout should therefore be the same as if it were T itself

I am not the original author of the library, so this might not be correct. In practice, however, this is how it works with current versions of the Rust compiler.

MabezDev avatar Aug 26 '24 18:08 MabezDev