[英]Is the ManuallyDrop ABI guaranteed to be repr(transparent)?
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.
[...] 如果单个字段是 pub,或者如果其布局以散文形式记录,则此 repr 仅被视为类型的公共 ABI 的一部分。 Otherwise, the layout should not be relied upon by other crates.
否则,布局不应被其他板条箱所依赖。
ManuallyDrop<T>
is repr(transparent)
, but its single field is not pub
. ManuallyDrop<T>
是repr(transparent)
,但它的单个字段不是pub
。 Its docs say:它的文档说:
[...] This wrapper is 0-cost.
[...] 这个包装器是 0 成本的。
ManuallyDrop<T>
is subject to the same layout optimizations asT
.ManuallyDrop<T>
与T
进行相同的布局优化。 [...][...]
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>
?假设我可以将 T 转换或以其他方式转换(例如指针转换)为
ManuallyDrop<T>
T
安全?
This was actually just clarified with today's release of Rust 1.61.0 .这实际上刚刚在今天发布的Rust 1.61.0中得到了澄清。 The documentation of
ManuallyDrop
now specifies (added text highlighted in bold): ManuallyDrop
的文档现在指定(添加的文本以粗体突出显示):
ManuallyDrop<T>
is guaranteed to have the same layout asT
, and is subject to the same layout optimizations asT
.ManuallyDrop<T>
保证与T
具有相同的布局,并进行与T
相同的布局优化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.