1 # Tuple and tuple indexing expressions
5 > **<sup>Syntax</sup>**\
7 > `(` [_InnerAttribute_]<sup>\*</sup> _TupleElements_<sup>?</sup> `)`
10 > ( [_Expression_] `,` )<sup>+</sup> [_Expression_]<sup>?</sup>
12 Tuples are written by enclosing zero or more comma-separated expressions in
13 parentheses. They are used to create [tuple-typed](types/tuple.html)
22 You can disambiguate a single-element tuple from a value in parentheses with a
26 (0,); // single-element tuple
27 (0); // zero in parentheses
30 ### Tuple expression attributes
32 [Inner attributes] are allowed directly after the opening parenthesis of a
33 tuple expression in the same expression contexts as [attributes on block
36 ## Tuple indexing expressions
38 > **<sup>Syntax</sup>**\
39 > _TupleIndexingExpression_ :\
40 > [_Expression_] `.` [TUPLE_INDEX]
42 [Tuples](types/tuple.html) and [struct tuples](items/structs.html) can be
43 indexed using the number corresponding to the position of the field. The index
44 must be written as a [decimal literal](tokens.html#integer-literals) with no
45 underscores or suffix. Tuple indexing expressions also differ from field
46 expressions in that they can unambiguously be called as a function. In all
47 other aspects they have the same behavior.
50 # struct Point(f32, f32);
52 assert_eq!(pair.1, 2);
53 let unit_x = Point(1.0, 0.0);
54 assert_eq!(unit_x.0, 1.0);
57 [Inner attributes]: attributes.html
58 [TUPLE_INDEX]: tokens.html#integer-literals
59 [_Expression_]: expressions.html
60 [_InnerAttribute_]: attributes.html
61 [attributes on block expressions]: expressions/block-expr.html#attributes-on-block-expressions