1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-27 16:25:43 +02:00

Move struct update syntax to speaker notes (#2597)

This commit is contained in:
Nicole L 2025-02-06 09:51:43 -08:00 committed by GitHub
parent ca137b4807
commit e1ed6eaf47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,9 +27,6 @@ fn main() {
let age = 39;
let avery = Person { name, age };
describe(&avery);
let jackie = Person { name: String::from("Jackie"), ..avery };
describe(&jackie);
}
```
@ -49,8 +46,20 @@ Key Points:
not important.
- If you already have variables with the right names, then you can create the
struct using a shorthand.
- The syntax `..avery` allows us to copy the majority of the fields from the old
struct without having to explicitly type it all out. It must always be the
last element.
## More to Explore
- You can also demonstrate the struct update syntax here:
```rust,ignore
let jackie = Person { name: String::from("Jackie"), ..avery };
```
- It allows us to copy the majority of the fields from the old struct without
having to explicitly type it all out. It must always be the last element.
- It is mainly used in combination with the `Default` trait. We will talk about
struct update syntax in more detail on the slide on the `Default` trait, so we
don't need to talk about it here unless students ask about it.
</details>