-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This should be quick, but introduces the syntax and the concept of a ZST.
- Loading branch information
Showing
3 changed files
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
minutes: 2 | ||
--- | ||
|
||
# Empty Structs | ||
|
||
Sometimes we just need a type, without any data. The only value of such a type | ||
has the same name as the type. This is a zero-sized type (ZST). | ||
|
||
```rust,editable | ||
struct NullMessageDestination; | ||
fn main() { | ||
let _message_destination = NullMessageDestination; | ||
// ... | ||
} | ||
``` | ||
|
||
ZSTs will be useful when we talk about traits and generics on day 2. | ||
|
||
<details> | ||
|
||
- This is a shorthand for a tuple struct with zero tuple elements. | ||
- There isn't much to see here, yet, but students might imagine a trivial | ||
implementation of an interface may have no data to store. | ||
|
||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters