## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

[type.struct]

# Struct types

[type.struct.intro]

A `struct` type is a heterogeneous product of other types, called the fields of the type.1

[type.struct.constructor]

New instances of a `struct` can be constructed with a struct expression.

[type.struct.layout]

The memory layout of a `struct` is undefined by default to allow for compiler optimizations like field reordering, but it can be fixed with the `repr` attribute. In either case, fields may be given in any order in a corresponding struct expression; the resulting `struct` value will always have the same memory layout.

[type.struct.field-visibility]

The fields of a `struct` may be qualified by visibility modifiers, to allow access to data in a struct outside a module.

[type.struct.tuple]

A tuple struct type is just like a struct type, except that the fields are anonymous.

[type.struct.unit]

A unit-like struct type is like a struct type, except that it has no fields. The one value constructed by the associated struct expression is the only value that inhabits such a type.

1. `struct` types are analogous to `struct` types in C, the record types of the ML family, or the struct types of the Lisp family. ↩