• BB_C@programming.dev
    link
    fedilink
    arrow-up
    4
    ·
    5 hours ago

    Who is even the target audience of this post? Beginners (which included all of us once) ask for all sorts of things. But these features didn’t happen in Rust for a reason.

    Named parameters are not needed in the age of LSP hints, where this exists as an editor feature (including (neo)vim).

    But if you really want named parameters AND optionals/defaults, rust always allowed the args struct pattern:

    struct Args<'a> {
      a: &'a str,
      b: u64,
      c: Option<u64>,
    }
    
    impl<'a> Default for Args<'a> {
      fn default() -> Self {
        Self {
           a: "hi", // default
           b: 3, // default
           c: None, // optional default
        }
      }
    }
    
    takes_args(Args{a: "not hi", ..Args::default()})
    

    The builder pattern is more about valid initialization, but does interact with the arg struct pattern when you have non-default (forced) arguments, although even then, you can not use it by having:

    struct Args<'a> {
      forced_arg1: &'a str,
      forced_arg2: u8,
      defaults: DefaultArgs, // implements Default
    }
    

    So mentioning the builder pattern is out of place.

    Overloading is not used because we have traits (and the sound subset of specialization for when that’s needed).

    So all in all, those “features” didn’t make it to Rust not because of the backlog, or for simplicity’s sake, but because idiomatic Rust (and even modern tooling in general, a la LSP) have alternatives that give you what you want and more.

    Everything mentioned above should be known by anyone who knew Rust for more than a month.