3 > **<sup>Syntax</sup>**
5 > _StructStruct_
6 > | _TupleStruct_
9 > `struct`
11 > [_Generics_]<sup>?</sup>
12 > [_WhereClause_]<sup>?</sup>
13 > ( `{` _StructFields_<sup>?</sup> `}` | `;` )
16 > `struct`
18 > [_Generics_]<sup>?</sup>
19 > `(` _TupleFields_<sup>?</sup> `)`
20 > [_WhereClause_]<sup>?</sup>
24 > _StructField_ (`,` _StructField_)<sup>\*</sup> `,`<sup>?</sup>
27 > [_OuterAttribute_]<sup>\*</sup>
28 > [_Visibility_]
29 > [IDENTIFIER] `:` [_Type_]
32 > _TupleField_ (`,` _TupleField_)<sup>\*</sup> `,`<sup>?</sup>
35 > [_OuterAttribute_]<sup>\*</sup>
36 > [_Visibility_]
37 > [_Type_]
39 A _struct_ is a nominal [struct type] defined with the keyword `struct`.
41 An example of a `struct` item and its use:
44 struct Point {x: i32, y: i32}
45 let p = Point {x: 10, y: 11};
49 A _tuple struct_ is a nominal [tuple type], also defined with the keyword
50 `struct`. For example:
52 [struct type]: types.html#struct-types
53 [tuple type]: types.html#tuple-types
56 struct Point(i32, i32);
57 let p = Point(10, 11);
58 let px: i32 = match p { Point(x, _) => x };
61 A _unit-like struct_ is a struct without any fields, defined by leaving off the
62 list of fields entirely. Such a struct implicitly defines a constant of its
63 type with the same name. For example:
67 let c = [Cookie, Cookie {}, Cookie, Cookie {}];
74 const Cookie: Cookie = Cookie {};
75 let c = [Cookie, Cookie {}, Cookie, Cookie {}];
78 The precise memory layout of a struct is not specified. One can specify a
79 particular layout using the [`repr` attribute].
81 [`repr` attribute]: attributes.html#ffi-attributes
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