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

Document behavior of enum when casted to an integer #10

Closed
jmi2k opened this issue Mar 13, 2017 · 7 comments
Closed

Document behavior of enum when casted to an integer #10

jmi2k opened this issue Mar 13, 2017 · 7 comments
Labels
Question Request for comments about the direction of the reference

Comments

@jmi2k
Copy link

jmi2k commented Mar 13, 2017

Consider the following example:

enum Foo {
    A,
    B,
    C
}

fn main() {
    println!("{}", Foo::A as usize);
    println!("{}", Foo::B as usize);
    println!("{}", Foo::C as usize);
}

The current behavior is that Foo members get casted to an increasing sequence starting from 0. Although that seems to be the most reasonable default, it should be documented to make clear that it won't be changed in the future.

@frewsxcv
Copy link
Member

Somewhat related, the book has a section on casting semantics that maybe should be copied/moved into the reference:

https://doc.rust-lang.org/book/casting-between-types.html

Though, it doesn't look like there's much there on enum casting

@steveklabnik
Copy link
Member

@aturon so, here's an interesting wrinkle. We were talking about getting the lang team and the docs team together to tackle issues like this one, but given this is in the nursery and not rust-lang, I can't cc @rust-lang/lang 😦

@steveklabnik steveklabnik added the Question Request for comments about the direction of the reference label Mar 13, 2017
@aturon
Copy link
Member

aturon commented Mar 13, 2017

@steveklabnik Whelp! I guess there are basically two options here:

  • Add in the teams to the nursery, which would probably be useful across the board.
  • Move the reference to rust-lang.

I'm not sure what the status of the latter is. Was there some particular "graduation" point we had in mind?

@steveklabnik
Copy link
Member

Was there some particular "graduation" point we had in mind?

I said "hey @alexcrichton ! Should this go in the nursery or rust-lang. I don't care." He shugged. So we asked @brson. He said "Eh given its level of polish let's put it in the nursery", to which alex and I said 🆒 .

So, it was basically a coinflip, and we didn't have any particular criteria set up.

@aturon
Copy link
Member

aturon commented Mar 13, 2017

@steveklabnik

Heh, alright! Let's keep this in mind when we set up the docs + lang team discussion soon.

@alercah
Copy link
Contributor

alercah commented Jan 2, 2018

@frewsxcv
Copy link
Member

frewsxcv commented Jan 3, 2018

yep! looks like @Havvy took care of this in #156 🎉

@frewsxcv frewsxcv closed this as completed Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Request for comments about the direction of the reference
Projects
None yet
Development

No branches or pull requests

5 participants