Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to wrap C enums in Rust?

Tags:

c

rust

Is it possible to wrap C enums in Rust?

For example C enum example

like image 792
Maik Klein Avatar asked Oct 17 '13 17:10

Maik Klein


1 Answers

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.

like image 52
huon Avatar answered Nov 07 '22 00:11

huon