# Structs

> **Syntax**  
> _Struct_ :  
>       _StructStruct_  
>    | _TupleStruct_  
>  
> _StructStruct_ :  
>    `struct`
>   [IDENTIFIER] 
>   [_Generics_]?
>   [_WhereClause_]?
>   ( `{` _StructFields_? `}` | `;` )  
>  
> _TupleStruct_ :  
>    `struct`
>   [IDENTIFIER] 
>   [_Generics_]?
>   `(` _TupleFields_? `)`
>   [_WhereClause_]?
>   `;`  
>  
> _StructFields_ :  
>    _StructField_ (`,` _StructField_)\* `,`?  
>  
> _StructField_ :  
>    [_OuterAttribute_]\*  
>    [_Visibility_]
>    [IDENTIFIER] `:` [_Type_]  
>  
> _TupleFields_ :  
>    _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:

```rust
struct Point {x: i32, y: i32}
let p = Point {x: 10, y: 11};
let px: i32 = p.x;
```

A _tuple struct_ is a nominal [tuple type], also defined with the keyword
`struct`. For example:

[struct type]: types.html#struct-types
[tuple type]: types.html#tuple-types

```rust
struct Point(i32, i32);
let p = Point(10, 11);
let px: i32 = match p { Point(x, _) => x };
```

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:

```rust
struct Cookie;
let c = [Cookie, Cookie {}, Cookie, Cookie {}];
```

is equivalent to

```rust
struct Cookie {}
const Cookie: Cookie = Cookie {};
let c = [Cookie, Cookie {}, Cookie, Cookie {}];
```

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/generics.html
[_WhereClause_]: items/generics.html#where-clauses
[_Visibility_]: visibility-and-privacy.html
[_Type_]: types.html
