多くは前の個体の値を使用しつつ、変更する箇所もある形で新しい個体を生成できる記法
struct User {
username: String,
email: String,
sign_in_count: u64,
active: bool,
}
fn main() {
let user1 = User {
username: String::from("username1"),
email: String::from("[email protected]"),
active: true,
sign_in_count: 1,
};
let user2 = User {
username: String::from("username2"),
email: String::from("[email protected]"),
..user1 //構造体更新記法でuser1から残りの欄の値を引き継ぐ
};
println!("{}", user2.username); //username2
}