1. 9
  1.  

    1. 6

      I have relatively recently discovered https://docs.rs/bon/latest/bon/ ,and it satisifes all my named arguments / builder needs. Once I see my function starts needing too many arguments or they get error-prone (e.g. same type), I just #[builder] on it, fix errors and job done.

      1. 1

        In the medium term, you might get away with using default field values for many cases where you’d use a builder today.

        https://github.com/rust-lang/rfcs/blob/master/text/3681-default-field-values.md

      2. 2

        One way to get this in idiomatic rust is to take newtypes (that are Copy). Takes a little bit of boilerplate but your function can then take a width arg of type Width and so on. Callers can do thatfunction(Width(w), Height(h)), and it all straightens out.

        1. 1

          I wonder what would be the impact on the compilation time.

          1. 1

            Named arguments would be so useful. I wish more languages had them. Structs can imitate them but they make things a lot more verbose. You have to pick a name, callers have to import/qualify it, you have to decide what traits to derive, give it its own documentation, etc. Newtypes can also imitate them, but they turn “I don’t want to identify this argument positionally” into “this thing deserves its own type” and they require lots of wrapping and unwrapping in places other than the function call.