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

Rename C-like enum to Field-less enum #157

Merged
merged 2 commits into from
Dec 5, 2017
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
14 changes: 8 additions & 6 deletions src/items/enumerations.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ In this example, `Cat` is a _struct-like enum variant_, whereas `Dog` is simply
called an enum variant. Each enum instance has a _discriminant_ which is an
integer associated to it that is used to determine which variant it holds.

## C-like Enumerations
## Custom Discriminant Values for Field-Less Enumerations

If there is no data attached to *any* of the variants of an enumeration it is
called a *c-like enumeration*. If a discriminant isn't specified, they start at
zero, and add one for each variant, in order. Each enum value is just its
discriminant which you can specify explicitly:
If there is no data attached to *any* of the variants of an enumeration,
then the discriminant can be directly chosen and accessed.

If a discriminant isn't specified, they start at zero, and add one for each
variant, in order. Each enum value is just its discriminant which you can
specify explicitly:

```rust
enum Foo {
Expand All @@ -58,7 +60,7 @@ hand side and specify the memory layout.

[`repr` attribute]: attributes.html#ffi-attributes

You can also cast a c-like enum to get its discriminant:
You can also cast a field-less enum to get its discriminant:

```rust
# enum Foo { Baz = 123 }
Expand Down