Last Updated: January 01, 2017
· pornel

Using C enums in Rust

If you try to use an enum in an extern C function declaration you'll get a warning:

found enum type without foreign-function-safe representation annotation in foreign module, #[warn(ctypes)] on by default

What Rust is trying to say is that C and Rust may use different integer sizes for the enum, so you need to tell Rust to use size same as C. You do that with #[repr(C)] annotation:

enum Foo {
    BAR, BAZ, QUZ,