Some commenters persuaded by reusability argument
6 Sep 24 7:12 PM · 1d ago · 3 comments · 1 source · development 6 of 6
Counterargument emerges: using structs allows configuration to be passed and reused across multiple function calls, offering flexibility that pure named arguments wouldn't provide. This benefit shifts some readers' views on the tradeoff.
“Having that as a struct makes it trivial to do so, while arguments would force you to either make your own…”
gavinmorrowitamarst Rust developer / authorSteve Klabnik Rust contributor (referenced)ekuber Rust team member
The whole story postscomments the bright band is this development · numbered dots are the others · click one to jump
What people said 3 voices · verbatim
-
I wish you could do this with enums. I really love how in Swift, you can do stuff like `let color = .red`. It would be nice to be able to do `let color = _::Red;` in Rust.
-
I had previously been in favor of named arguments, but I think this convinces me. Once you add keyword arguments, you have to add a whole host of other features *that already exist*, just for structs instead of functions. The other benefit of using a struct when there are so many parameters is that you can now pass around that configuration in…
-
If you were to have default field values and elided struct names, you could instead have this. While it is still more verbose, it does become much more reasonable. (Even if you didn't have elided struct names, it wouldn't be too bad.) You can also then pass around `RequestOptions` in other code as you like, for example if you have a bunch of calls…
All 6 developments of Rust dev argues structs beat named arguments for API design →
LobstersHacker News