Skip to content

Commit 6e4d2c3

Browse files
committed
Add example
1 parent 4ba0917 commit 6e4d2c3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ Structs with default layout are zero-sized, if they contain no fields of
128128
non-zero size. That is, either the type has no fields, or all of its fields have
129129
zero size.
130130

131+
For example, all these types are zero-sized:
132+
133+
```rust
134+
# use std::mem::size_of;
135+
struct Zst0;
136+
struct Zst1(Zst0);
137+
struct Zst2(Zst1, Zst0);
138+
# fn main() {
139+
# assert_eq!(size_of::<Zst0>(), 0);
140+
# assert_eq!(size_of::<Zst1>(), 0);
141+
# assert_eq!(size_of::<Zst2>(), 0);
142+
# }
143+
```
144+
131145
#### Unresolved questions
132146

133147
During the course of the discussion in [#11] and [#12], various

0 commit comments

Comments
 (0)