Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compound-types.md #139

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions training-slides/src/compound-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ struct Point {
}
```

Note:

The fields may not be laid out in memory in the order they are written (unless
you ask the compiler to ensure that they are).

## Construction

- there is no partial initialization
Expand Down Expand Up @@ -143,8 +148,17 @@ fn main() {

## Enums with Values

- An enum is the same size, no matter which variant is picked
- It will be the size of the largest variant
- An enum value is the same size, no matter which variant is picked
- It will be the size of the largest variant (plus a tag)

Note:

The tag in an enum specifies which variant is currently valid, and is stored as the
smallest integer the compiler can get away with - it depends how many variants you
have. Of course, if none of the variants have any data, the enum is *just* the tag.

If you have a C background, you can think of this as being a `struct` containing an `int`
and a `union`.

## Doing a `match` on an `enum`

Expand Down
Loading