mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-09 12:36:57 +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:
parent
dbc11b2df2
commit
d4c0099781
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user