Reading in a .h file from C

Does rust support C style enums?

I have a C program with an enumeration in a header file. I'm trying to write an assembler in rust and I'd like to be able to read the C enum directly into rust. Is there any easy way to do this without having to lex/parse the file?

#ifndef _INCLUDED_H_OPCODES
#define _INCLUDED_H_OPCODES

enum eOpcodes
  {
   opcode_nop=0x00,
   opcode_mov_r1_Const1=0x01,
   opcode_mov_r2_Const1=0x02,
   opcode_mov_r3_Const1=0x03,
   opcode_mov_r4_Const1=0x04,
 };
 #endif

The bindgen crate can generate rust bindings based on C header files.

3 Likes