1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-05 20:02:37 +02:00

Added speaker notes to enum sizes (#201)

* Added speaker notes to enum sizes

* Update sizes.md

Just formatting

Co-authored-by: Fabian Bornhofen <fbornhofen@google.com>
This commit is contained in:
Charisee Chiw 2023-01-20 13:55:30 -08:00 committed by GitHub
parent dbc11b2df2
commit d4c0099781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,6 +30,9 @@ fn main() {
<details>
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<bool>` is another example of tight packing.
* For [some types](https://doc.rust-lang.org/std/option/#representation), Rust guarantees that `size_of::<T>()` equals `size_of::<Option<T>>()`.
* Zero-sized types allow for efficient implementation of `HashSet` using `HashMap` with `()` as the value.