是否可以在Rust中包装C枚举?

Mai*_*ein 6 c rust

是否可以在Rust中包装C枚举?

例如C enum示例

huo*_*uon 6

是的,没有任何变化(除了空白以适应当前的Rust风格):

enum List {
    MaxLogLevel = 1,
    MaxNumMessages,
    TrilinearFiltering,
    MaxAnisotropy,
    TexCompression,
    SRGBLinearization,
    LoadTextures,
    FastAnimation,
    ShadowMapSize,
    SampleCount,
    WireframeMode,
    DebugViewMode,
    DumpFailedShaders,
    GatherTimeStats
}

fn main() {
    println!("{} {} {}",
             MaxLogLevel as uint,
             SampleCount as uint,
             GatherTimeStats as uint);
}
Run Code Online (Sandbox Code Playgroud)

打印1 10 14.

  • @MaikKlein,不是真的.[这个(目前有点被攻击的)PR](https://github.com/mozilla/rust/pull/9613)让用户可以控制枚举的大小,这将使这更容易,但一般来说,C API使用枚举很难与其他语言交互(正因为C编译器大多可以根据自己的意愿自由选择枚举的大小). (2认同)