Skip to content

Commit

Permalink
Add option to generate safe and unsafe conversions for rustified enums
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Jan 7, 2025
1 parent 59a43e1 commit 554d030
Show file tree
Hide file tree
Showing 8 changed files with 599 additions and 139 deletions.
2 changes: 2 additions & 0 deletions bindgen-integration/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ fn setup_macro_test() {
.enable_cxx_namespaces()
.default_enum_style(EnumVariation::Rust {
non_exhaustive: false,
safe_conversion: false,
unsafe_conversion: false,
})
.raw_line("pub use self::root::*;")
.raw_line("extern { fn my_prefixed_function_to_remove(i: i32); }")
Expand Down
100 changes: 100 additions & 0 deletions bindgen-tests/tests/expectations/tests/issue-2646.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions bindgen-tests/tests/headers/issue-2646.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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'

enum Plain {
Plain1,
Plain2,
Plain3
};

enum TryFromRaw {
TFR1 = -1,
TFR2 = 5,
TFR3
};

enum FromRawUnchecked {
FRU1 = 6,
FRU2 = 10,
FRU3 = 11,
};

enum Both {
Both1,
Both2 = -1,
Both3,
};

enum NonExhaustive {
Ex1,
Ex2,
};
Loading

0 comments on commit 554d030

Please sign in to comment.