by nitsky · 5y ago · 0 comments
This would allow a syntax more familiar to users of JavaScript, where fields with their default value can be omitted:
struct Person {
name: String,
email: Option<String> = None,
}
let person = Person {
name: "John Doe".to_owned(),
..
}; #[derive(Default)]
struct Person {
name: String,
email: Option<String>,
}
fn main() {
let person = Person {
name: "John Doe".to_owned(),
..Default::default()
};
}Forgetting a required field just means you get the dummy value from Default, that is, if you even manage to implement Default for the struct at all (the required fields may not have a sensible default value)