3 stable releases

1.0.2 Apr 7, 2022
1.0.1 Mar 3, 2022
1.0.0 Mar 2, 2022

#1126 in Procedural macros

Download history 2/week @ 2024-02-19 5/week @ 2024-02-26 61/week @ 2024-04-01

61 downloads per month

MIT license

9KB
152 lines

crates.io docs.rs license

cpreprocess

Stupid and cursed Rust procedural macro that runs a C preprocessor on the input

Usage

[dependencies]
cpreprocess = "*"

Example

fn main() {
    cpreprocess::cpreprocess!(r#"
        #define MACRO(NAME) fn print_ ## NAME () { println!("hello world"); }

        MACRO(hello_world)

        print_hello_world()
    "#)
}

Nightly

If you're using the Rust nightly compiler, you can use the macro without a string literal. Just enable the nightly Cargo feature for this crate.

I think this is largely experimental, as it relies on a non-100% accurate method of extracting the contents of the macro.

fn main() {
    cpreprocess::cpreprocess! {
        #define MACRO(NAME) fn print_ ## NAME () { println!("hello world"); }

        MACRO(hello_world)

        print_hello_world()
	}
}

Dependencies

~2MB
~45K SLoC