Crates.io | c_defines_to_enum |
lib.rs | c_defines_to_enum |
version | 0.1.1 |
source | src |
created_at | 2024-04-03 16:31:03.522531 |
updated_at | 2024-04-07 06:55:53.414053 |
description | A procedural macro for generate enum from C defines statement. |
homepage | https://github.com/Oyami-Srk/c-defines-to-enum |
repository | https://github.com/Oyami-Srk/c-defines-to-enum |
max_upload_size | |
id | 1195204 |
size | 11,673 |
Turn C Style #define
statement into enum
in Rust.
Providing exactly one enum name. And string literal with name content
to generate enums from C defines.
Content could be evaluated from macros like include_str!
.
This crate is crafted to use under no_std
environment.
use c_defines_to_enum::parse_c_defines_to_enum;
use std::convert::TryFrom;
parse_c_defines_to_enum!(
TestEnum,
to_lower = true,
content = include_str!("test.h")
);
fn it_works() {
println!("{:?}", TestEnum::try_from(1234));
let value: usize = TestEnum::test1.into();
println!("{:?} = {}", TestEnum::test1, value);
}
Result:
Ok(test1)
test1 = 1234
#define A B
#define B 1000
Into<usize>
#[repr(usize)]
and TryFrom<usize>
/Into<usize>
are fixed.pub