You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A struct expression with fields enclosed in parentheses constructs a tuple struct.
123
-
Though it is listed here as a specific expression for completeness, it is equivalent to a [call expression] to the tuple struct's constructor. For example:
121
+
A struct expression with fields enclosed in parentheses constructs a tuple struct or a tuple variant of an enum.
122
+
Though it is listed here as a specific expression for completeness, it is equivalent to a [call expression] to the tuple struct's (enum tuple variant's) constructor. For example:
124
123
125
124
```rust
126
125
structPosition(i32, i32, i32);
127
126
Position(0, 0, 0); // Typical way of creating a tuple struct.
128
127
letc=Position; // `c` is a function that takes 3 arguments.
129
128
letpos=c(8, 6, 7); // Creates a `Position` value.
129
+
130
+
enumVersion { Triple(i32, i32, i32) };
131
+
Version::Triple(0, 0, 0);
132
+
letf=Version::Triple;
133
+
letver=f(8, 6, 7);
130
134
```
131
135
136
+
> [!NOTE]
137
+
> While the grammar permits qualified paths, the last segment can't be a type alias:
138
+
>
139
+
> ```rust
140
+
> traitTr { typeT; }
141
+
> impl<T> TrforT { typeT=T; }
142
+
>
143
+
> structTuple();
144
+
> enumEnum { Tuple() }
145
+
>
146
+
> // <Unit as Tr>::T(); // causes an error -- `::T` is a type, not a value
147
+
> <EnumasTr>::T::Tuple(); // OK
148
+
> ```
149
+
132
150
r[expr.struct.unit]
133
151
## Unitstructexpression
134
152
135
-
A unit struct expression is just the path to a unit struct item.
136
-
This refers to the unit struct's implicit constant of its value.
137
-
The unit struct value can also be constructed with a fieldless struct expression. For example:
0 commit comments