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 (eg 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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.