(no title)
aazaa | 4 years ago
I'm surprised the article doesn't mention Default:
https://doc.rust-lang.org/std/default/trait.Default.html
It can be combined with the rest pattern to yield something very similar to the solution the author is after.
https://stackoverflow.com/questions/19650265/is-there-a-fast...
davidkunz|4 years ago
The caller needs to know that the input struct implements Default.
And you would need one input struct per function (if default values differ).
Are there better ways or is it planned to introduce something like default parameters?
steveklabnik|4 years ago
Narann|4 years ago
It's a question of taste, but the builder pattern can be considered a “better way”, because of how clunky the use of Default can be.
You would prefer an API with easier to read, documented builders than the ..Default::default() call.
nicoburns|4 years ago
khuey|4 years ago
delta1|4 years ago
hota_mazi|4 years ago
More details about this and what else is lacking in Rust compared to Kotlin:
https://medium.com/@cedricbeust/what-rust-could-learn-from-k...
slashink|4 years ago
tristan957|4 years ago