Commenters propose syntax improvements to reduce struct boilerplate
4 Yesterday 4:51 PM · 18h ago · 5 comments · 1 source · development 4 of 6
Multiple commenters suggest language features that could make the struct-based approach less verbose: Zig-style inferred struct names (underscore placeholders), mixed required/optional fields via a PartialDefault trait, and enum type inference. These proposals indicate dissatisfaction with the verbosity of the current workaround.
“I wish Rust had Zig's inferred struct name…becomes just _ { x: 10, y: 20, … }”
yshuiitamarst 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 5 voices · verbatim
-
https://doc.rust-lang.org/unstable-book/language-features/default-field-values.html I plan on stabilizing that before the end of the year. There's only one blocker around semantics and it is being actively worked on.
-
> you can't seriously say this about Rust, a very complex language; the extra complexity isn't much compared to what's already in there. Keeping an eye on the complexity budget to stave off becoming the next C++ "just one more little thing" at a time has been deep in Rust's RFC process since the beginning. Hell, Rust RFCs were I learned the…
-
I wish Rust had Zig's inferred struct name. i.e. this: ```rust let cropped = image::imageops::crop_imm( &img, Crop { x: 10, y: 20, width: 200, height: 100, }, ); ``` becomes ```rust let cropped = image::imageops::crop_imm( &img, _ { x: 10, y: 20, width: 200, height: 100, }, ); ```
-
My man! Not 100% what I was thinking, but this is great. For my use case I'm thinking something like this: ``` #[PartialDefault] struct Contact { #[required] address: Address, #[optional] favorite_color: Option } ``` Then someone could: ``` Contact { address: &home, ..PartialDefault::default } ``` But this would not be allowed to `Contact {…
-
There is some chance that Rust will implement this maybe by the next edition
All 6 developments of Rust dev argues structs beat named arguments for API design →
LobstersHacker News