#transpiler #c #proc-macro

macro cdefines

A proc macro that translates c #define constants to rust consts

5 releases

0.1.4 Jun 5, 2022
0.1.3 Oct 21, 2020
0.1.2 May 12, 2019
0.1.1 May 12, 2019
0.1.0 May 12, 2019

#563 in Procedural macros

MIT license

9KB
116 lines

cdefines

Turn #define C codes into Rust constants.

How to use:

Add to code:

extern crate cdefines;

#[cdefines::preprocessor]
const IOCTL: &str = 
    "#define TCGETS		0x5401
    #define TCSETS		0x5402
    #define TCSETSW		0x5403
    #define TCSETSF		0x5404";

It gets translated to:

const IOCTL_TCGETS: usize = 0x5401;
// ...
enum IOCTL {
    TCGETS = 0x5401,
    // ...
}

What is supported

  1. Plain integers(hex, oct, bin, dec) e.g. #define A 0x1234.
  2. Simple define cascading e.g. #define A 123 and then #define B A.

Dependencies

~79KB