From 50d8656945513c6b327122e5a40650c66baa87cb Mon Sep 17 00:00:00 2001 From: Alexis Beingessner Date: Tue, 7 Jul 2015 09:39:21 -0700 Subject: [PATCH] void types --- exotic-sizes.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/exotic-sizes.md b/exotic-sizes.md index 8e05485055f..ea8dc86d1f0 100644 --- a/exotic-sizes.md +++ b/exotic-sizes.md @@ -3,6 +3,10 @@ Most of the time, we think in terms of types with a fixed, positive size. This is not always the case, however. + + + + # Dynamically Sized Types (DSTs) Rust also supports types without a statically known size. On the surface, @@ -34,19 +38,20 @@ a variable position based on its alignment.** + + # Zero Sized Types (ZSTs) Rust actually allows types to be specified that occupy *no* space: ```rust struct Foo; // No fields = no size -enum Bar; // No variants = no size // All fields have no size = no size struct Baz { foo: Foo, - bar: Bar, - qux: (), // empty tuple has no size + qux: (), // empty tuple has no size + baz: [u8; 0], // empty array has no size } ``` @@ -67,3 +72,16 @@ standard allocators (including jemalloc, the one used by Rust) generally conside passing in `0` as Undefined Behaviour. + + + +# Void Types + +Rust also enables types to be declared that *cannot even be instantiated*. These +types can only be talked about at the type level, and never at the value level. + +```rust +enum Foo { } // No variants = VOID +``` + +TODO: WHY?! \ No newline at end of file