Commit 58b85a2
committed
allow renaming rules for C enums, structs, and typedefs
```rust
// true to enable debug output as warnings
let mut ren = Renamer::new(true);
// rename a single item, e.g. a struct, enum, or a typedef
ren.rename_item("my_struct", "MyStruct");
// rename an enum and its values
rename_enum!(
ren,
"my_enum" => "MyEnum", // rename the enum itself
remove: "^I_SAID_", // optionally any number of "remove" regexes
remove: "_ENUM$",
case: Pascal, // optionally set case convert, defaults to "PascalCase"
"MV_IT" => "Value1", // rename a specific value after pattern removal
"MV_IT2" => "Value2", // more specific value renames
);
let bindings = Builder::default()
// in real code, use .header("path/to/header.h")
.header_contents("test.h", r#"
struct my_struct {
int a;
};
enum my_enum {
I_SAID_YES_ENUM,
I_SAID_NO_ENUM,
I_SAID_MV_IT_ENUM,
I_SAID_MV_IT2_ENUM,
};
"#)
.rustified_enum(ren.get_regex_str())
.parse_callbacks(Box::new(ren))
.generate().unwrap();
}
/////////// generated code
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct MyStruct {
pub a: ::std::os::raw::c_int,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum MyEnum {
Yes = 0,
No = 1,
Value1 = 2,
Value2 = 3,
}
```1 parent 97ab915 commit 58b85a2
File tree
6 files changed
+353
-3
lines changed- bindgen
- ir
6 files changed
+353
-3
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
398 | | - | |
| 398 | + | |
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | | - | |
| 402 | + | |
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | | - | |
| 406 | + | |
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| |||
1312 | 1314 | | |
1313 | 1315 | | |
1314 | 1316 | | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
1315 | 1353 | | |
1316 | 1354 | | |
1317 | 1355 | | |
| |||
0 commit comments