The nomicon says:
repr(transparent)
[...] This repr is only considered part of the public ABI of a type if either the single field is pub, or if its layout is documented in prose. Otherwise, the layout should not be relied upon by other crates.
ManuallyDrop<T> is repr(transparent), but its single field is not pub. Its docs say:
[...] This wrapper is 0-cost.
ManuallyDrop<T>is subject to the same layout optimizations asT. [...]
Does this count as documenting its layout in the prose? Is it safe to assume that I can transmute or otherwise convert (e.g. pointer cast) from T to ManuallyDrop<T>?
This was actually just clarified with today's release of Rust 1.61.0. The documentation of ManuallyDrop now specifies (added text highlighted in bold):
ManuallyDrop<T>is guaranteed to have the same layout asT, and is subject to the same layout optimizations asT.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With