Pre-RFC: User-provided default field values

So the current idea is that this won't be directly related to the actual Default trait?

IMO that makes sense, if you consider that stuff like the following is already valid currently:

struct A(i32);

struct B(f32);

struct C([&'static str; 4]);

struct NoTraitImplsAnywhere {
    a: A,
    b: B,
    c: C,
}

const DEFAULT_INSTANCE: NoTraitImplsAnywhere = NoTraitImplsAnywhere {
    a: A(99),
    b: B(24.6),
    c: C(["this", "sentence", "isn't", ""]),
};

fn main() {
    let mut x = DEFAULT_INSTANCE;
    x.c.0[2] = "is";
    x.c.0[3] = "complete";
    println!("a: {}, b: {}, c: {:?}", x.a.0, x.b.0, x.c.0);
}

The derive(Default) would use this, but this wouldn't use Default. So if the type has defaults for every field, the derived impl Default will just do Self { .. }.

2 Likes

Got it. Sounds like a "best of both worlds" solution then, I'd say.

1 Like

Just a status update because I said I'd be working on it over the weekend. I am slowly but surely pulling parts of Centril's RFC, narrowing parts, expanding parts, etc. I assure you that I'll update the post as soon as it's written in full.

Part of the delay is that I'm rewriting everything to be easily readable, even for non-native speakers. I don't know if there are any RFCs that have followed high-level guidelines of simplified technical English, but that's what I'm aiming for. It's a very different style for sure.

2 Likes