Skip to content

Commit 5465cc0

Browse files
committed
Elaborate on how union constructors produce union values
1 parent 5964acc commit 5465cc0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: src/types/union.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ The memory layout of a `union` is undefined by default (in particular, fields do
2525
fix a layout.
2626

2727
r[type.union.value]
28-
A value of a union type consists of a sequence of bytes, corresponding to each [value byte][type.struct.value.value-bytes]. The value bytes of a union are represented exactly. Each [padding byte][type.struct.value.padding] is set to uninit.
28+
A value of a union type consists of a sequence of bytes, corresponding to each [value byte][type.struct.value.value-bytes]. The value bytes of a union are represented exactly. Each [padding byte][type.struct.value.padding] is set to uninit when encoded.
2929

3030
> [!NOTE]
31-
> When a union value is constructed or a field is read/written to, the value of that field is encoded or decoded appropriately.
31+
> A given value byte is guaranteed allowed to be uninit if it is padding in any field, recursively expanding union fields. Whether a byte of a union is allowed to be uninit in any other case is not yet decided.
32+
33+
r[type.union.constructor]
34+
The constructor of a union type encodes the initialized field value into the corresponding bytes of the union, and sets all bytes that are not used by the field to uninit.
35+
36+
r[type.union.field-access]
37+
When a field is written to by a field access expression, the value written is encoded into the corresponding bytes of the union. When a field is read, the value of that field is decoded from the corresponding bytes.
3238

3339
[`Copy`]: ../special-types-and-traits.md#copy
3440
[item]: ../items/unions.md

0 commit comments

Comments
 (0)