Add example of struct update syntax
This commit is contained in:
parent
1dfa283017
commit
ea1a37f9ef
1 changed files with 14 additions and 6 deletions
|
|
@ -7,15 +7,23 @@ struct User {
|
|||
}
|
||||
|
||||
fn build_user(email: String, username: String) -> User {
|
||||
User {
|
||||
email,
|
||||
username,
|
||||
active: true,
|
||||
sign_in_count: 0,
|
||||
}
|
||||
User {
|
||||
email,
|
||||
username,
|
||||
active: true,
|
||||
sign_in_count: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let user = build_user(String::from("Heisenberg"), String::from("mail@mail.com"));
|
||||
println!("Hello to the User: {:?}!", user);
|
||||
|
||||
let user2 = User {
|
||||
username: String::from("Jesse"),
|
||||
email: String::from("mail@mail.com"),
|
||||
..user
|
||||
};
|
||||
|
||||
println!("Hello to the User: {:?}!", user2);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue