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.

I probably misunderstand, but just in case: Would implementing Default manually help?

I believe they want a shorthand for

Mixed {
    b: NoDefault,
    // some sugar here resulting in
    a: Default::default(),
    c: Default::default(),
}

which some newcomers think is what ..Default::default() does.

(I'm not aware of any active effort for that capability offhand.)

In this case, no. The problem is that the macro that I'm generating the builder struct with can't determine which fields implement Default and which don't. The only other option is to annoyingly require the user to annotate each field for the macro, which defeats the purpose.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.