Structs
Syntax
Struct :
StructStruct
| TupleStructStructStruct :
struct
IDENTIFIER GenericParams? WhereClause? ({
StructFields?}
|;
)TupleStruct :
struct
IDENTIFIER GenericParams?(
TupleFields?)
WhereClause?;
StructFields :
StructField (,
StructField)*,
?StructField :
OuterAttribute*
Visibility?
IDENTIFIER:
TypeTupleFields :
TupleField (,
TupleField)*,
?TupleField :
OuterAttribute*
Visibility?
Type
A struct is a nominal struct type defined with the keyword struct
.
An example of a struct
item and its use:
A tuple struct is a nominal tuple type, also defined with the keyword
struct
. For example:
A unit-like struct is a struct without any fields, defined by leaving off the list of fields entirely. Such a struct implicitly defines a constant of its type with the same name. For example:
is equivalent to
The precise memory layout of a struct is not specified. One can specify a
particular layout using the repr
attribute.