diff options
author | Andrew Clayton <a.clayton@nginx.com> | 2023-09-05 20:24:29 +0100 |
---|---|---|
committer | Andrew Clayton <a.clayton@nginx.com> | 2023-09-05 20:35:44 +0100 |
commit | 76f8f41487e361c00099a729dee2e293a4b713a5 (patch) | |
tree | 5adc4aa9747b304585e5466759e8ec497da94454 /src/rust/unit-wasm-sys/macros.rs | |
parent | 6764e6e8ac3f1223536c35d7daef0755df144643 (diff) | |
download | unit-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/macros.rs')
-rw-r--r-- | src/rust/unit-wasm-sys/macros.rs | 8 |
1 files changed, 4 insertions, 4 deletions
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; |