Rust community discusses alternative approaches to optional arguments
2 Sep 22 12:29 AM · 2d ago · 1 post · 4 comments · 1 source · development 2 of 3
The essay sparked discussion on Lobsters with commenters proposing alternative language designs. Mitsuhiko suggested optional structural types with anonymous struct literals; ptrettner discussed function overloading by shape; and senekor proposed struct type inference at instantiation sites as middle grounds between convenience and clarity.
“IMO the optimal way would be for Rust to have optional structural types and then an anonymous struct literal with `..` to mean filling in defaults”
mitsuhikoSteve Klabnik Programming language designer, Rust community member
The whole story postscomments the bright band is this development · numbered dots are the others · click one to jump
What people said 4 voices · verbatim
-
IMO the optimal way would be for Rust to have optional structural types and then an anonymous struct literal with `..` to mean filling in defaults: ```rust let cropped = image::imageops::crop_imm({ image: &img, x: 10, y: 20, width: 200, height: 100, .. // brings in the rest }); ``` //EDIT: I know that this precise syntax is probably impossible to…
-
function overloading has tons of variations but I want to call out one axis I'm experiment with in my own (as-of-yet private) language: "function overloading by type" vs "function overloading by shape". And the experiment is how far you can get by only overload "by shape". Which means you overload by number of args and/or by the name of the named…
-
I often think anonymous structs / records would be nice in Rust. nitpick: the last line should probably be `..Default::default()`, to stay consistent with named structs. But I think a lot of the convenience here could already be achieved if the struct's name could be inferred at instantiation site. Imagine something like this: ```rs fn main() {…
-
> nitpick: the last line should probably be ..Default::default(), to stay consistent with named structs. No, that would be intentional and have `Default::default()` be automatically added by the compiler if no filler is provided. `Default` is already in a few APIs anyways (eg: `mem::take` or `unwrap_or_default`). I don't think it would be…
All 3 developments of Steve Klabnik on Rust's resistance to fancy argument… →
Hacker NewsLobsters