File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,18 @@ struct Foo {
72
72
(In fact, one may use such field names in patterns or in accessor
73
73
expressions like ` foo.0 ` .)
74
74
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:
76
87
77
88
- ` #[repr(Rust)] ` -- the default.
78
89
- ` #[repr(C)] ` -- request C compatibility
You can’t perform that action at this time.
0 commit comments