Skip to content

Commit 50d8656

Browse files
committed
void types
1 parent 987a868 commit 50d8656

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

exotic-sizes.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Most of the time, we think in terms of types with a fixed, positive size. This
44
is not always the case, however.
55

6+
7+
8+
9+
610
# Dynamically Sized Types (DSTs)
711

812
Rust also supports types without a statically known size. On the surface,
@@ -34,19 +38,20 @@ a variable position based on its alignment.**
3438

3539

3640

41+
42+
3743
# Zero Sized Types (ZSTs)
3844

3945
Rust actually allows types to be specified that occupy *no* space:
4046

4147
```rust
4248
struct Foo; // No fields = no size
43-
enum Bar; // No variants = no size
4449

4550
// All fields have no size = no size
4651
struct Baz {
4752
foo: Foo,
48-
bar: Bar,
49-
qux: (), // empty tuple has no size
53+
qux: (), // empty tuple has no size
54+
baz: [u8; 0], // empty array has no size
5055
}
5156
```
5257

@@ -67,3 +72,16 @@ standard allocators (including jemalloc, the one used by Rust) generally conside
6772
passing in `0` as Undefined Behaviour.
6873

6974

75+
76+
77+
78+
# Void Types
79+
80+
Rust also enables types to be declared that *cannot even be instantiated*. These
81+
types can only be talked about at the type level, and never at the value level.
82+
83+
```rust
84+
enum Foo { } // No variants = VOID
85+
```
86+
87+
TODO: WHY?!

0 commit comments

Comments
 (0)