Skip to content

Document behavior of enum when casted to an integer #10

Closed
@jmi2k

Description

@jmi2k

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionRequest for comments about the direction of the reference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions