you are viewing a single comment's thread
view the rest of the comments
[–] 6 points 1 month ago (3 children)

With newtypes you can also emulate named args with a single struct. This also allows them to be passed on together.

struct RectArgs{
    x:i32,
    y:32,
    w:32,
    h:32,
}
impl Default for RectArgs{...}

Then the call site looks like this:

rect(RectArgs{
    x:0,
    y:0,
    w:30,
    h:20,
}
// with default arguments
rect(RectArgs{
    w:30,
    h:20,
    .. RectArgs::default ()
}
  • source
  • parent
  • hideshow 3 child comments
  • [–] 1 point 1 month ago* (last edited 1 month ago) (2 children)

    Yeah, though in those cases you might get an extra question about why rect is a function and not a method, e.g.

    Rect {
         w: 30,
         h: 20,
         .. RectArgs::default()
    }.do_the_thing()
    
  • source
  • parent
  • hideshow 2 child comments