| Section | Title |
|---|---|
| 1 | Struct Declarations |
| 2 | Field Access |
| 3 | Methods as Functions |
| 4 | Enums |
| 5 | Tagged Unions |
| 6 | Packed Structs |
| 7 | Data Layout |
| 8 | Exercises |
Struct DeclarationsA struct is a type made from named fields.
Field AccessFields are selected with the dot operator.
Methods as FunctionsZig has no class syntax.
EnumsAn enum is a type whose values come from a fixed set of names.
Tagged UnionsA union is a value that may hold one of several types.
Packed StructsA normal struct is laid out for ordinary program use. The compiler may add padding between fields so that each field has a suitable address.
Data LayoutA struct is not only a list of fields. It also has a layout in memory.
ExercisesThese exercises close the chapter on structs, enums, and unions. They are meant to make the data model concrete.