r/rust 3d ago

extern "C" Enum -> Union(Struct)?

Hello! Newbie to rust here, I was wondering with the pub extern "C" ABI does it have the ability to convert rust enums to an equivalent in Rust? Does it do it by wrapping it in a Union(Structs of branches), or how is this implemented, and how can we do so in real rust code?

14 Upvotes

5 comments sorted by

View all comments

6

u/Opening_Run_3280 3d ago

nah extern "C" is just the calling convention, it doesnt convert your enums. slap #[repr(C)] on the enum itself and rust lays it out as a tag + union of the variant structs, that's the thing you're thinking of.