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:
commit
9448ae3e19
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user