Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/items/structs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Structs

> **<sup>Syntax</sup>**
> _Struct_ :
> &nbsp;&nbsp; &nbsp;&nbsp; _StructStruct_
> &nbsp;&nbsp; | _TupleStruct_
>
> _StructStruct_ :
> &nbsp;&nbsp; `struct`
> [IDENTIFIER]&nbsp;
> [_Generics_]<sup>?</sup>
> [_WhereClause_]<sup>?</sup>
> ( `{` _StructFields_<sup>?</sup> `}` | `;` )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it help to have this match the text and split this into StructStruct and UnitStruct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I considered that when I first reviewed @brauliobz 's grammar and found a reason against it. Not sure anymore though. I'd rather not mess with the PR anymore than needed right now.

>
> _TupleStruct_ :
> &nbsp;&nbsp; `struct`
> [IDENTIFIER]&nbsp;
> [_Generics_]<sup>?</sup>
> `(` _TupleFields_<sup>?</sup> `)`
> [_WhereClause_]<sup>?</sup>
> `;`
>
> _StructFields_ :
> &nbsp;&nbsp; _StructField_ (`,` _StructField_)<sup>\*</sup> `,`<sup>?</sup>
>
> _StructField_ :
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup>
> &nbsp;&nbsp; [_Visibility_]
> &nbsp;&nbsp; [IDENTIFIER] `:` [_Type_]
>
> _TupleFields_ :
> &nbsp;&nbsp; _TupleField_ (`,` _TupleField_)<sup>\*</sup> `,`<sup>?</sup>
>
> _TupleField_ :
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup>
> &nbsp;&nbsp; [_Visibility_]
> &nbsp;&nbsp; [_Type_]

A _struct_ is a nominal [struct type] defined with the keyword `struct`.

An example of a `struct` item and its use:
Expand Down Expand Up @@ -43,3 +79,10 @@ The precise memory layout of a struct is not specified. One can specify a
particular layout using the [`repr` attribute].

[`repr` attribute]: attributes.html#ffi-attributes

[_OuterAttribute_]: attributes.html
[IDENTIFIER]: identifiers.html
[_Generics_]: items.html#type-parameters
[_WhereClause_]: items.html#type-parameters
[_Visibility_]: visibility-and-privacy.html
[_Type_]: types.html