Consider that we have a large automatically generated file(s) of C-style definitions of the form:
// header.h
#define DEFINITION_1 0x12335
#define DEFINITION_2 0x4567566
#define DEFINITION_3 0x6666
//..................
#define DEFINITION_N 0x56657
Now, in my Rust program I am interested in having some very specific of these definitions to be embedded in different places/modules, such as
pub const DEF_2: SomeType = SomeType::new(0x4567566); // The value in the constructor is
// corresponding the the definition
// in the header
It would be nice if there was some way to have a macro magic!()
with a usage as follows:
pub const DEF_2: SomeType = SomeType::new(magic!("header.h", DEFINITION_2));
Now, I am aware of Bindgen, but it will indiscriminately generate all of definitions that are in allow-list or aren’t blacklisted. These lists will have to be manually adjusted each time another definition is needed or removed, it will also dump it into a single file. While the magic!
will only pull the required definition just in the place it is needed at. Is this something that is possible with the current state of Rust?