How to specify the representation type for an enum in Rust to interface with C++?

后端 未结 1 455
忘了有多久
忘了有多久 2020-12-11 19:37

Is there a way I can make a C++ style enumeration with explicit representation type in Rust? Example:

enum class Number: int16_t {
    Zero, One, Two, Three,         


        
1条回答
  •  我在风中等你
    2020-12-11 19:58

    You can specify a representation for the enum.

    #[repr(i16)]
    enum Foo {
        One = 1,
        Two = 2,
    }
    

    0 讨论(0)
提交回复
热议问题