Add example of struct update syntax

This commit is contained in:
laurens 2020-05-22 13:41:50 +02:00
parent 1dfa283017
commit ea1a37f9ef

View file

@ -7,15 +7,23 @@ struct User {
} }
fn build_user(email: String, username: String) -> User { fn build_user(email: String, username: String) -> User {
User { User {
email, email,
username, username,
active: true, active: true,
sign_in_count: 0, sign_in_count: 0,
} }
} }
fn main() { fn main() {
let user = build_user(String::from("Heisenberg"), String::from("mail@mail.com")); let user = build_user(String::from("Heisenberg"), String::from("mail@mail.com"));
println!("Hello to the User: {:?}!", user); 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);
} }