File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed
src/coding-guidelines/types-and-traits Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 2929 Unions allow multiple fields to occupy the same memory, similar to C unions.
3030 Unlike enumeration types, unions do not track which field is currently active.
3131 You must ensure that when a field is read,
32- the underlying bytes are valid for that field' s type [1 ]_.
32+ the underlying bytes are valid for that field' s type [UNION ]_.
3333
3434 Every type has a *validity invariant* — a set of constraints that all values of
35- that type must satisfy [2 ]_.
35+ that type must satisfy [VALID ]_.
3636 Reading a union field performs a *typed read*,
3737 which asserts that the bytes are valid for the target type.
3838 Violating this invariant is undefined behavior.
289289 :header-rows: 0
290290 :widths: 5 85
291291
292- * - .. [1 ]
292+ * - .. [UNION ]
293293 - The Rust Project Developers. " Rust Reference: Unions." *The Rust Reference*, n.d. https:// doc.rust-lang.org/reference/items/unions.html.
294- * - .. [2 ]
294+ * - .. [VALID ]
295295 - Rust Unsafe Code Guidelines Working Group. " Validity and Safety Invariant." *Rust Unsafe Code Guidelines*, n.d. https:// rust-lang.github.io/unsafe-code-guidelines/glossary.html#validity-and-safety-invariant.
296296
297297>>>>>>> c93b2cb (Update types-and -traits.rst):src/coding-guidelines/types-and-traits.rst
You can’t perform that action at this time.
0 commit comments