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

Add enum namespacing to the Guide. #19616

Merged
merged 1 commit into from
Dec 9, 2014
Merged

Conversation

steveklabnik
Copy link
Member

Closes #19556.

Notice that we need both the enum name and the variant name: `StringResult::StringOK`, but
we didn't need to with `Ordering`, we just said `Greater` rather than `Ordering::Greater`.
There's a reason: the Rust prelude imports the variants of `Ordering` as well as the enum
itself. We can use the `use` keyword to do something similar with `StringResult`:
Copy link
Member

Choose a reason for hiding this comment

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

The current use of Ordering the prelude is currently a subject of a bit of debate (rust-lang/rfcs#497, rust-lang/rfcs#504), would it be possible to write this without referencing the prelude or Ordering at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would love to have it removed, but until then, the guide is still deficient. What's the timeline on the RFC getting accepted? I'd rather not have the guide be wrong for weeks.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I was thinking that we could accept this now if an example other than Ordering was used. Perhaps Option which will likely always be in the prelude?

Copy link
Member Author

Choose a reason for hiding this comment

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

I chose Ordering for a few reasons. One is that it's a classic pattern in C which is different than in Rust. Secondly because it fits nicely into the classic guessing game example. Removing the Ordering example invovles changing almost the first half of the guide.

We do talk about Option in the section with variants, which we haven't gotten to yet at this point, IIRC. Or at least, that's why we do Ordering first: enum without variants, then one with.

Copy link
Member

Choose a reason for hiding this comment

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

Ok! We can revise slightly as necessary as the prelude changes later on in that case.

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Dec 9, 2014
@bors bors merged commit e294772 into rust-lang:master Dec 9, 2014
@@ -1160,6 +1160,55 @@ Where a `StringResult` is either an `StringOK`, with the result of a computation
`ErrorReason` with a `String` explaining what caused the computation to fail. These kinds of
`enum`s are actually very useful and are even part of the standard library.

Enum variants are namespaced under the enum names. For example, here is an example of using
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a wee tidbit - I think it might be unnecessary to use "example" twice in

For example, here is an example...

Perhaps this sentence could just be "Here is an example using our StringResult:" ?

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.

Guide does not explain the namespaced enums
4 participants