Skip to content

Commit

Permalink
Move struct update syntax to speaker notes (#2597)
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison authored Feb 6, 2025
1 parent ca137b4 commit e1ed6ea
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/user-defined-types/named-structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
```

Expand All @@ -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>

0 comments on commit e1ed6ea

Please sign in to comment.