You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are some parts of the language with special-cased interaction based on the size information ot types. The plain core::mem::transmute requires the compiler to prove size-equivalence of two types, in a much less generic setting than the type bounds themselves suggest. The core::mem::transmute_copy requires the caller to unsafely uphold that the first parameter is not smaller than the second. And zero sized types (ZST) have additional properties:
They are not really allocated but instead are expressed as dangling pointers.
Transparent wrapper types are allowed to have an arbitrary number of zero-sized fields without losing the property of inheriting the layout of a single non-zero-sized field, especially if the alignment requirement of the ZST itself is 1.
All ZSTs have the exact same validity requirements: none.
These properties allow skipping or entirely eliding some validity checks. This is the size equivalent of Unaligned for alignment. For example, transmuting into a ZST can never violate its validity requirements and is always sound, although it might violate a type's safety requirements. This does not imply that all ZSTs implement ZeroSafe, which is also concerned with safety requirements.
Prior art
zerocopy and bytemuck do not have this concept.
typic has SizeOf which is an alias to <T as Layout>::Size where the Size associated type of Layout is an typenum::marker_traits::Unsigned.
The text was updated successfully, but these errors were encountered:
There are some parts of the language with special-cased interaction based on the size information ot types. The plain
core::mem::transmute
requires the compiler to prove size-equivalence of two types, in a much less generic setting than the type bounds themselves suggest. Thecore::mem::transmute_copy
requires the caller tounsafely
uphold that the first parameter is not smaller than the second. And zero sized types (ZST) have additional properties:1
.These properties allow skipping or entirely eliding some validity checks. This is the size equivalent of
Unaligned
for alignment. For example, transmuting into a ZST can never violate its validity requirements and is always sound, although it might violate a type's safety requirements. This does not imply that all ZSTs implementZeroSafe
, which is also concerned with safety requirements.Prior art
zerocopy
andbytemuck
do not have this concept.typic
hasSizeOf
which is an alias to<T as Layout>::Size
where theSize
associated type ofLayout
is antypenum::marker_traits::Unsigned
.The text was updated successfully, but these errors were encountered: