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

TRPL: Fix the enums chapter #25348

Merged
merged 4 commits into from
May 13, 2015
Merged

TRPL: Fix the enums chapter #25348

merged 4 commits into from
May 13, 2015

Conversation

geofft
Copy link
Contributor

@geofft geofft commented May 12, 2015

The enums chapter at the moment is ... weird. The examples aren't about enums, they're about structs, and most of the chapter talks about how enums don't support comparison operators by default (which is also true of other compound data types.) I think there was a story here once, but some coherency got lost in refactoring.

There are two preliminary patches here, one to combine the struct and tuple-struct chapters, and one to document unit-like structs, because enum syntax is easier to explain once you have those three. The final patch moves the enum chapter after the struct chapter, and rewrites most of it to talk about enums usefully (including covering matches on enums).

r? @steveklabnik

`Character` to be either a `Digit` or something else.
relates a set of alternates to a specific name. Each variant of an
`enum` is defined like a struct, and can hold any data (or no data, like
a unit-like struct).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how I feel about this characterization. I can see where you're coming from, but these things are very separate in my brain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly going for the fact that, syntactically, each variant of an enum is written like one of the ways to write a struct definition. If you're getting at, e.g., people wrongly thinking that you can use a variant of an enum as a standalone thing (like write an impl for a single enum variant), then yeah, I get that distinction. Would rephrasing this to make it clear that it's about syntax, not (so much) semantics, help?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that might make it better :)

@steveklabnik
Copy link
Member

Hey @geofft !

Thanks for this. Looking back at those chapters, it's true that there's a little lack of coherency now. I still feel that enums belong before match, as they're perfectly suited for each other. I like a large number of these changes, but do have some nits.

@geofft
Copy link
Contributor Author

geofft commented May 12, 2015

I still feel that enums belong before match, as they're perfectly suited for each other

The match chapter doesn't match on enums at the moment, so I put enums immediately after match, so that I could give an example of exhaustive matches on enums (which I think is one of the most useful things about them, and also a good example of tagged unions in particular) without having to explain match.

If you want to do structs, enums, and then matches, then we should put an example of matching on enum variants in the matches chapter. I can update the PR to do that.

@steveklabnik
Copy link
Member

Yeah, let's do that move. :)

Do you have time to make these changes in the next few hours? The deadline for what makes it in is approaching quickly, and since this is TOC change, I'd like to make it in.

@geofft
Copy link
Contributor Author

geofft commented May 12, 2015

I'm on a train with spotty wifi, but yes, I'll rebase this branch shortly to take your comments into account. I think I also want to rework the first paragraph, since "sum type" is not particularly explanatory, so I may pull the discussion of tags up there.

@steveklabnik
Copy link
Member

since "sum type" is not particularly explanatory

We generally are interested in using actual CS terms in the docs, but linking to the glossary to explain them.

no worries, i'm gonna go get dinner, so take your time ❤️

@geofft
Copy link
Contributor Author

geofft commented May 13, 2015

@steveklabnik, just wanted to make sure you saw the new push -f (I'm not sure if GitHub notifies on that). I've moved the final match example over to match.md.

@steveklabnik
Copy link
Member

Ah! It doesn't. Let me check it out

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented May 13, 2015

📌 Commit f59f41e has been approved by steveklabnik

@steveklabnik
Copy link
Member

manually merged into #25352

steveklabnik added a commit to steveklabnik/rust that referenced this pull request May 13, 2015
The enums chapter at the moment is ... weird. The examples aren't about enums, they're about structs, and most of the chapter talks about how enums don't support comparison operators by default (which is also true of other compound data types.) I think there was a story here once, but some coherency got lost in refactoring.

There are two preliminary patches here, one to combine the struct and tuple-struct chapters, and one to document unit-like structs, because enum syntax is easier to explain once you have those three. The final patch moves the enum chapter after the struct chapter, and rewrites most of it to talk about enums usefully (including covering matches on enums).

r? @steveklabnik
bors added a commit that referenced this pull request May 13, 2015
@bors bors merged commit f59f41e into rust-lang:master May 13, 2015
@geofft geofft deleted the trpl-fix-enums branch May 24, 2015 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants