Open
Description
From #31: If you have homogeneous structs, where all the N
fields are of a single type T
, can we guarantee a mapping to the memory layout of [T; N]
? How do we map between the field names and the indices? What about zero-sized types?
A specific proposal:
- If all fields have the same type
T
(ignoring zero-sized types), then the layout will be the same as[T; N]
whereN
is the number of fields - If the struct is defined with named fields, the mapping from fields to their indices is undefined (so
foo.bar
maps an undefined index) - If the struct is defined as a tuple struct (or a tuple), then the indices are derived from the definition (so
foo.0
maps to[0]
)
This is basically because it's convenient but also because it's about the only sensible thing to do (unless you imagine we might want to start inserting padding between random fields or something, which connects to #35).
Note that for tuple structs (and tuples), the ordering of (public) fields is also significant for semver and other purposes -- changing the ordering will affect your clients. The same is not true for named fields and so this proposal attempts to avoid making it true.