|
1 | 1 | # Structs
|
2 | 2 |
|
| 3 | +> **<sup>Syntax</sup>** |
| 4 | +> _Struct_ : |
| 5 | +> _StructStruct_ |
| 6 | +> | _TupleStruct_ |
| 7 | +> |
| 8 | +> _StructStruct_ : |
| 9 | +> `struct` |
| 10 | +> [IDENTIFIER] |
| 11 | +> [_Generics_]<sup>?</sup> |
| 12 | +> [_WhereClause_]<sup>?</sup> |
| 13 | +> ( `{` _StructFields_<sup>?</sup> `}` | `;` ) |
| 14 | +> |
| 15 | +> _TupleStruct_ : |
| 16 | +> `struct` |
| 17 | +> [IDENTIFIER] |
| 18 | +> [_Generics_]<sup>?</sup> |
| 19 | +> `(` _TupleFields_<sup>?</sup> `)` |
| 20 | +> [_WhereClause_]<sup>?</sup> |
| 21 | +> `;` |
| 22 | +> |
| 23 | +> _StructFields_ : |
| 24 | +> _StructField_ (`,` _StructField_)<sup>\*</sup> `,`<sup>?</sup> |
| 25 | +> |
| 26 | +> _StructField_ : |
| 27 | +> [_OuterAttribute_]<sup>\*</sup> |
| 28 | +> [_Visibility_] |
| 29 | +> [IDENTIFIER] `:` [_Type_] |
| 30 | +> |
| 31 | +> _TupleFields_ : |
| 32 | +> _TupleField_ (`,` _TupleField_)<sup>\*</sup> `,`<sup>?</sup> |
| 33 | +> |
| 34 | +> _TupleField_ : |
| 35 | +> [_OuterAttribute_]<sup>\*</sup> |
| 36 | +> [_Visibility_] |
| 37 | +> [_Type_] |
| 38 | +
|
3 | 39 | A _struct_ is a nominal [struct type] defined with the keyword `struct`.
|
4 | 40 |
|
5 | 41 | An example of a `struct` item and its use:
|
@@ -43,3 +79,10 @@ The precise memory layout of a struct is not specified. One can specify a
|
43 | 79 | particular layout using the [`repr` attribute].
|
44 | 80 |
|
45 | 81 | [`repr` attribute]: attributes.html#ffi-attributes
|
| 82 | + |
| 83 | +[_OuterAttribute_]: attributes.html |
| 84 | +[IDENTIFIER]: identifiers.html |
| 85 | +[_Generics_]: items.html#type-parameters |
| 86 | +[_WhereClause_]: items.html#type-parameters |
| 87 | +[_Visibility_]: visibility-and-privacy.html |
| 88 | +[_Type_]: types.html |
0 commit comments