dot notation
struct <name of Struct> {
name1: type,
name2: type,
name3: type,
}
let <name of instance> = <name of Struct> {
name1: value,
name2: value,
name3: value,
};
struct <name of Struct>(type, type, type, ...);
let <name of instance> = <name of Struct>(value, value, value, ...);
struct <name of Struct>
let <name of instance> = <name of Struct>
fn build_user(email: String, username: String) -> User {
User {
active: true,
username, // because the parameter name in the function's signature and the Struct field name are exactly the same, we can use the "field init shorthand".
email, // "field init shorthand" can also applied here.
sign_in_count: 1,
}
}
let user2 = User {
email: String::from("another@example.com"),
..user1 // all values except the email value are the same as user1.
};