Is it possible to wrap C enums in Rust?

2019-06-19 18:53发布

问题:

Is it possible to wrap C enums in Rust?

For example C enum example

回答1:

Yes, with no changes (other than whitespace to fit in with prevailing Rust style):

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);
}

Prints 1 10 14.



标签: c rust