summaryrefslogtreecommitdiff
path: root/Rust struct update syntax.md
blob: 299ac55fc82a3214e4a44f5f95aa7ca9f278f3a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Instantiate a new instance of a struct with most of the fields from an other instance:

```rust
struct User {
  name: String,
  email: String,
}

fn main () {
  let user1 = User {
    name: String::from("Jasper"),
    email: String::from("jaspert.ras@gmail.com"),
  }

  let user2 = User {
    email: String::from("maffe_jasper@hotmail.nl"),
    ..user1
  }
}
```

Will reuse `name` from `user1`.