4 ms·
The problem then is what should happen if you define two "anonymous structs" that share some members (name and type). Most users want these to be seamlessly ex
by zozbot234 4y ago
The problem then is what should happen if you define two "anonymous structs" that share some members (name and type). Most users want these to be seamlessly extensible, which amounts to full row types as seen in OCaml.
- brundolf 4y agoIt would be nice if subset-structs worked like they do in TypeScript, but I would still be totally happy if they had to be an exact match. Subset matching would probably be the 80% complexity for the 20% benefit Now... a neat compromise could be something like this fn foo<T: { bar: i32 }>(my_struct: T) { } foo({ bar: 12, stuff: "abc" }) That would fit a lot more smoothly into Rust's type system than the automatic subset-matching would, but even then, I'd be content without it. The most basic version of anonymous structs is hardly more than sugar over tuples, it just seems like such an easy win