Skip to content

Commit 39f1b4a

Browse files
committed
Add option to generate safe and unsafe conversions for rustified enums
1 parent 3e0094e commit 39f1b4a

File tree

9 files changed

+693
-228
lines changed

9 files changed

+693
-228
lines changed

bindgen-integration/build.rs

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ fn setup_macro_test() {
192192
.enable_cxx_namespaces()
193193
.default_enum_style(EnumVariation::Rust {
194194
non_exhaustive: false,
195+
safe_conversion: false,
196+
unsafe_conversion: false,
195197
})
196198
.raw_line("pub use self::root::*;")
197199
.raw_line("extern { fn my_prefixed_function_to_remove(i: i32); }")

bindgen-tests/tests/expectations/tests/issue-2646.rs

+100
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// bindgen-flags: --rustified-enum 'Plain.*' --rustified-enum 'TryFromRaw.*=try_from_raw' --rustified-enum='FromRawUnchecked.*=from_raw_unchecked' --rustified-enum='Both.*=try_from_raw,from_raw_unchecked' --rustified-enum 'NonExhaustive.*=non_exhaustive'
2+
3+
enum Plain {
4+
Plain1,
5+
Plain2,
6+
Plain3
7+
};
8+
9+
enum TryFromRaw {
10+
TFR1 = -1,
11+
TFR2 = 5,
12+
TFR3
13+
};
14+
15+
enum FromRawUnchecked {
16+
FRU1 = 6,
17+
FRU2 = 10,
18+
FRU3 = 11,
19+
};
20+
21+
enum Both {
22+
Both1,
23+
Both2 = -1,
24+
Both3,
25+
};
26+
27+
enum NonExhaustive {
28+
Ex1,
29+
Ex2,
30+
};

0 commit comments

Comments
 (0)