Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: FRU/Struct Update Syntax: ..Default::default() for non-Default Struct?
I seem to recall an old RFC that would make this code legal:
pub struct NoDefault;
pub struct Mixed {
a: u32,
b: NoDefault,
c: Option<NoDefault>,
}
fn foo() -> Mixed {
Mixed {
b: NoDefault,
..Default::default()
}
}
This unfortunately isn't covered by default_field_values
because as far as I can tell, that will require an explicit = default()
on each field going through #[derive(Default)]
. In this case I want to specify values manually for all of the non-default fields, and use Default
to fill in the remaining ones, without explicitly marking up the struct*. Does such an RFC or proposal/discussion exist?
* - Say, for example, this struct is a generated builder struct from a macro that can't tell which field is Default
or not.
2 posts - 2 participants
🏷️ rust_feed