Using C enums in Rust
If you try to use an enum in an extern C function declaration you'll get a warning:
found
enumtype 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:
#[repr(C)]
enum Foo {
BAR, BAZ, QUZ,
}Written by Kornel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rust
Authors
pornel
137.5K
bobwilliams
1.991K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#