1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-07-02 05:04:29 +02:00

Merge pull request #147 from fbornhofen/speaker-notes-enum-sizes

Expand enum sizes example and add speaker notes
This commit is contained in:
Martin Geisler
2023-01-10 17:44:07 +01:00
committed by GitHub

View File

@ -19,7 +19,19 @@ enum Foo {
fn main() {
dbg_size!(Foo);
dbg_size!(bool);
dbg_size!(Option<bool>);
dbg_size!(&i32);
dbg_size!(Option<&i32>);
}
```
* See the [Rust Reference](https://doc.rust-lang.org/reference/type-layout.html).
<details>
* `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.
</details>