mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-04 03:25:08 +02:00
Expand enum sizes example and add speaker notes
This commit is contained in:
parent
a5d31d759f
commit
8d2fb11adc
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user