this post was submitted on 22 Sep 2026
24 points (100.0% liked)

Rust

8294 readers
54 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 3 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] anton@lemmy.blahaj.zone 7 points 2 days ago (1 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 ()
}
[–] syklemil@discuss.tchncs.de 1 points 2 days ago* (last edited 2 days ago) (1 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()
[–] anton@lemmy.blahaj.zone 1 points 2 days ago (1 children)

I assumed the rect is a method on something like a graphics context or physics engine, but yeah.

[–] syklemil@discuss.tchncs.de 1 points 2 days ago

Yeah, decent assumption, I'll tone down my comment a bit.