Re:Rust for C++ Programmers Part 7: Data Types
by kzrdude on Saturday May 24, 2014 @07:14AM
(#7793101)
What they mean is that there would be special cases for let patterns so that
is a fine destructuring. It would be a special case for let, since the pattern would have to be more explicit in function arguments and in match, but I think they have a good point.
[ Parent
| on HN ]
Re:Rust for C++ Programmers Part 7: Data Types
by kibwen on Saturday May 24, 2014 @01:13PM
(#7793800)
I should emphasize that tuple structs are a somewhat obscure feature. Their main use case is to support newtyping:
struct Meters(f64);
struct Miles(f64);
let meters = Meters(10.4);
let miles = metric_to_imperial(meters);
let Miles(raw_miles) = miles;
The single-arity case above constitutes the vast majority of tuple struct usage. And, as you may expect, in any other context besides tuple structs a single-arity tuple is completely silly (the only reason that we have syntax for single-arity tuples at all is to make writing macros easier).Ultimately it's just not a feature that would be pulling its weight. If you want a structure with multiple fields where destructuring is not necessary, just use a struct in the first place. Honestly, if we found a better way to support newtyping then I wouldn't be sad if we got rid of tuple structs entirely.