Skip to content

Commit 58f5d8e

Browse files
committed
ASCII art for structs
1 parent f3781c2 commit 58f5d8e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

reference/src/layout/structs-and-tuples.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,18 @@ struct Foo {
7272
(In fact, one may use such field names in patterns or in accessor
7373
expressions like `foo.0`.)
7474

75-
Structs can have various `#[repr]` flags that influence their layout:
75+
When layout out a struct, the compiler in particular has to decide how the
76+
fields of the struct are arranged, which can be visualized as follows:
77+
```
78+
[ <--> [field 1] <-----> [field 2] <-> [ field 3 ] <--> ]
79+
```
80+
The individual fields are blocks of fixed size (determined by the field's
81+
layout). The compiler freely picks an order for the fields to be in (this does
82+
not have to be the order of declaration in the source), and it picks the gaps
83+
between the fields (under some constraints, such as alignment).
84+
85+
What exactly the compiler does, as well as other aspects of layout beyond size
86+
and field offset, can be controlled by a `#[repr]` attribute:
7687

7788
- `#[repr(Rust)]` -- the default.
7889
- `#[repr(C)]` -- request C compatibility

0 commit comments

Comments
 (0)