Is there any technical reason Rust is designed to use dot notation for tuples instead of using index notation (t[2]
)?
let t = (20u32, true, \'b\
This decision was made in RFC 184. The Motivation section has details:
Right now accessing fields of tuples and tuple structs is incredibly painful—one must rely on pattern-matching alone to extract values. This became such a problem that twelve traits were created in the standard library
(core::tuple::Tuple*)
to make tuple value accesses easier, adding.valN()
,.refN()
, and.mutN()
methods to help this. But this is not a very nice solution—it requires the traits to be implemented in the standard library, not the language, and for those traits to be imported on use. On the whole this is not a problem, because most of the timestd::prelude::*
is imported, but this is still a hack which is not a real solution to the problem at hand. It also only supports tuples of length up to twelve, which is normally not a problem but emphasises how bad the current situation is.
The discussion in the associated pull request is also useful.