Default Arguments (enum, struct)

enum EnFoo {
    Foo1,
    Foo2,
    Foo3,
}
impl Default for EnFoo {
    fn default() -> Self {
        Self::Foo1
    }
}
struct StFoo {
    foo1: usize,
    foo2: String,
    foo3: u8,
}
impl Default for StFoo {
    fn default() -> Self {
        Self {
            foo1: 0,
            foo2: String::from("0"),
            foo3: 0,
        }
    }
}

fn fooo(a1: EnFoo*, a2: StFoo*) {
    // ...
}
fn fooo_b_mut(a1: &mut EnFoo*, a2: &mut StFoo*) {
    // ...
}

// ****
    // EnFoo* <--- if EnFoo == empty place then
    // Create EnFoo::default()
// ****

    fooo(); /* <--- ==

    fn fooo(a1: EnFoo*, a2: StFoo*) {
        if EnFoo == empty then ↴
        ""let a1 = EnFoo::default();"" <-- Internal Execution

        if StFoo == empty then ↴
        ""let a2 = StFoo::default();"" <-- Internal Execution

        Now can be accessible
        a1, a2
    }
    */

How about this default arguments design that implemented the Default trait only for enum and structure??

Please share code in text, not in image.

3 Likes

Oh Thank you to notice me and sharing advice kindly, i didn't realize that things. Edited! Thank you.

What exactly are you asking?

Just suggests new feature about default arguments.

fn fooo(a0: &str, a1: SomeStruct*, a2: SomeEnum*) {
//...
}
fn main() {
    fooo("First");   // <---
}

Only for enums and structs which already implemented "Default" Trait.

They have [Type]* syntax

This has been suggested several times before.

At least with Named & Default Arguments - A Review, Proposal and Macro Implementation

But several other proposals have mentioned default args even if they weren't about it exclusively.

What does this proposal bring to the table that those proposals didn't?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.