summaryrefslogtreecommitdiffhomepage
path: root/src/rust/unit-wasm-sys
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2023-09-05 20:24:29 +0100
committerAndrew Clayton <a.clayton@nginx.com>2023-09-05 20:35:44 +0100
commit76f8f41487e361c00099a729dee2e293a4b713a5 (patch)
tree5adc4aa9747b304585e5466759e8ec497da94454 /src/rust/unit-wasm-sys
parent6764e6e8ac3f1223536c35d7daef0755df144643 (diff)
downloadunit-wasm-76f8f41487e361c00099a729dee2e293a4b713a5.tar.gz
unit-wasm-76f8f41487e361c00099a729dee2e293a4b713a5.tar.bz2
rust: Change how bindgen creates enums
Previously bindgen was picking the 'constified_enum'. E.g it would turn the luw_srb_flags_t enum typedef enum { LUW_SRB_NONE = 0x00, LUW_SRB_APPEND = 0x01, LUW_SRB_ALLOC = 0x02, LUW_SRB_FULL_SIZE = 0x04, LUW_SRB_FLAGS_ALL = (LUW_SRB_NONE|LUW_SRB_APPEND|LUW_SRB_ALLOC| LUW_SRB_FULL_SIZE) } luw_srb_flags_t; into pub const luw_srb_flags_t_LUW_SRB_NONE: luw_srb_flags_t = 0; pub const luw_srb_flags_t_LUW_SRB_APPEND: luw_srb_flags_t = 1; pub const luw_srb_flags_t_LUW_SRB_ALLOC: luw_srb_flags_t = 2; pub const luw_srb_flags_t_LUW_SRB_FULL_SIZE: luw_srb_flags_t = 4; pub const luw_srb_flags_t_LUW_SRB_FLAGS_ALL: luw_srb_flags_t = 7; But then this requires some further changes to make the names nicer without the type prefixed. This will only be exasperated when adding an enum containing the HTTP status codes... So instead, tell bindgen to use the 'rustified_enum' method which produces this pub enum luw_srb_flags_t { LUW_SRB_NONE = 0, LUW_SRB_APPEND = 1, LUW_SRB_ALLOC = 2, LUW_SRB_FULL_SIZE = 4, LUW_SRB_FLAGS_ALL = 7, } which in theory requires no extra changes (it doesn't with the http status codes enum), however in this specific case, because these are actually bitflags we still need to cast them to u32 so they can be OR'd. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to 'src/rust/unit-wasm-sys')
-rw-r--r--src/rust/unit-wasm-sys/build.rs3
-rw-r--r--src/rust/unit-wasm-sys/macros.rs8
2 files changed, 7 insertions, 4 deletions
diff --git a/src/rust/unit-wasm-sys/build.rs b/src/rust/unit-wasm-sys/build.rs
index 507099b..1f41afa 100644
--- a/src/rust/unit-wasm-sys/build.rs
+++ b/src/rust/unit-wasm-sys/build.rs
@@ -36,6 +36,9 @@ fn generate_bindings() {
.allowlist_function("^luw_.*")
.allowlist_var("^luw_.*")
.allowlist_type("^luw_.*")
+ .default_enum_style(bindgen::EnumVariation::Rust {
+ non_exhaustive: false,
+ })
.generate()
.expect("Unable to generate bindings");
diff --git a/src/rust/unit-wasm-sys/macros.rs b/src/rust/unit-wasm-sys/macros.rs
index 5914ad9..080d702 100644
--- a/src/rust/unit-wasm-sys/macros.rs
+++ b/src/rust/unit-wasm-sys/macros.rs
@@ -14,7 +14,7 @@ pub const LUW_VERSION_NUMBER: i32 =
(LUW_VERSION_MINOR << 16) |
(LUW_VERSION_PATCH << 8);
-pub const LUW_SRB_NONE: u32 = luw_srb_flags_t_LUW_SRB_NONE;
-pub const LUW_SRB_APPEND: u32 = luw_srb_flags_t_LUW_SRB_APPEND;
-pub const LUW_SRB_ALLOC: u32 = luw_srb_flags_t_LUW_SRB_ALLOC;
-pub const LUW_SRB_FULL_SIZE: u32 = luw_srb_flags_t_LUW_SRB_FLAGS_ALL;
+pub const LUW_SRB_NONE: u32 = luw_srb_flags_t::LUW_SRB_NONE as u32;
+pub const LUW_SRB_APPEND: u32 = luw_srb_flags_t::LUW_SRB_APPEND as u32;
+pub const LUW_SRB_ALLOC: u32 = luw_srb_flags_t::LUW_SRB_ALLOC as u32;
+pub const LUW_SRB_FULL_SIZE: u32 = luw_srb_flags_t::LUW_SRB_FLAGS_ALL as u32;