From d4c00997819b7cad08fd2fb325ea0f863e1b853c Mon Sep 17 00:00:00 2001 From: Charisee Chiw Date: Fri, 20 Jan 2023 13:55:30 -0800 Subject: [PATCH] Added speaker notes to enum sizes (#201) * Added speaker notes to enum sizes * Update sizes.md Just formatting Co-authored-by: Fabian Bornhofen --- src/enums/sizes.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/enums/sizes.md b/src/enums/sizes.md index fa013c6b..5736914d 100644 --- a/src/enums/sizes.md +++ b/src/enums/sizes.md @@ -29,9 +29,12 @@ fn main() { * See the [Rust Reference](https://doc.rust-lang.org/reference/type-layout.html).
- -* `Option` is another example of tight packing. -* For [some types](https://doc.rust-lang.org/std/option/#representation), Rust guarantees that `size_of::()` equals `size_of::>()`. -* Zero-sized types allow for efficient implementation of `HashSet` using `HashMap` with `()` as the value. + +Key Points: + * Internally Rust is using a field (discriminant) to keep track of the enum variant. + * As a niche optimization an enum discriminant is merged with the pointer so that `Option<&Foo>` is the same size as `&Foo`. + * `Option` is another example of tight packing. + * For [some types](https://doc.rust-lang.org/std/option/#representation), Rust guarantees that `size_of::()` equals `size_of::>()`. + * Zero-sized types allow for efficient implementation of `HashSet` using `HashMap` with `()` as the value.