Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move struct update syntax to speaker notes #2597

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>