1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-21 14:46:37 +02:00

Merge pull request #146 from fbornhofen/speaker-notes-variant-payloads

Add speaker notes for variant-payloads.md
This commit is contained in:
Martin Geisler 2023-01-10 17:44:49 +01:00 committed by GitHub
commit 9448ae3e19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,3 +6,11 @@ You can define richer enums where the variants carry data. You can then use the
```rust,editable ```rust,editable
{{#include ../../third_party/rust-by-example/webevent.rs}} {{#include ../../third_party/rust-by-example/webevent.rs}}
``` ```
<details>
* In the above example, accessing the `char` in `KeyPress`, or `x` and `y` in `Click` only works within a `match` statement.
* `match` inspects a hidden discriminant field in the `enum`.
* `WebEvent::Click { ... }` is not exactly the same as `WebEvent::Click(Click)` with a top level `struct Click { ... }`. The inlined version cannot implement traits, for example.
</details>