this post was submitted on 22 Sep 2026
24 points (100.0% liked)
Rust
8294 readers
32 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
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
view the rest of the comments
I'm used to named arguments from other languages, and that makes me fairly partial to them. Having to tool around with builders feels a lot more complex and clunky.
That said, I do wonder at how many of the usecases aren't workarounds for long argument lists that are either stringly typed, or something similar. As in, with a signature of
(i32,i32,i32,i32) -> whatever, named arguments seem like a way of getting the compiler to catch errors in confusing{x,y}_{position,length}; but if the signature were newtypes likeRect(Origin(i32,i32), Size(i32, i32)) -> whatever, then the felt need for named arguments drops considerably.With newtypes you can also emulate named args with a single struct. This also allows them to be passed on together.
Then the call site looks like this:
Yeah, though in those cases you might get an extra question about why
rectis a function and not a method, e.g.I assumed the rect is a method on something like a graphics context or physics engine, but yeah.
Yeah, decent assumption, I'll tone down my comment a bit.
Newtypes have their uses, but as a replacement for named arguments they are an overkill in many cases. They solve different problems.
Newtypes are beneficial when some domain-specific value with an invariant is used extensively throughout the codebase. You would use them to store and pass around that value without fear that something goes wrong.
However if we start to create a type for each parameter of every function (which may not be related at all), it would only result in a lot of unnecessary boilerplate. Named arguments is a simple and elegant solution for calling a function in a more explicit way, nothing more.