summaryrefslogtreecommitdiffhomepage
path: root/src/rust/unit-wasm-sys/macros.rs
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2023-08-24 20:03:25 +0100
committerAndrew Clayton <a.clayton@nginx.com>2023-08-25 21:13:49 +0100
commit55a41414b87301e37d9dc35937694d5aa13d9d99 (patch)
treebd19eacf97c5b3888ea89f502c6105bd3b5712d3 /src/rust/unit-wasm-sys/macros.rs
parent5f8623b45b1ff9c96f0db57fcc41eb5e1bbca90e (diff)
downloadunit-wasm-55a41414b87301e37d9dc35937694d5aa13d9d99.tar.gz
unit-wasm-55a41414b87301e37d9dc35937694d5aa13d9d99.tar.bz2
Rust: Add a nicer wrapper around the libunit-wasm bindings
This adds a nice wrapper (aka rusty) around the generated libunit-wasm bindings. This should provide a more native rust like experience with the following benefits - No casting. So no things like 'as *mut c_void' - Native rust strings. So no things like '.as_ptr() as *const c_char' - Better ctx initialisation. Filed initialisation is now hidden away - Great reduction in the amount of unsafe {} blocks required - Generally more compact There are also some new macros - C2S!() converts a CStr to a Str - S2C!() converts a formatted Str to a Cstr using format!() - uwr_write_str!() a wrapper around luw_mem_writep_data and format!() This wrapper uses a uwr (Unit Wasm Rust) prefix under a 'rusty' namespace. The luw_http_hdr_iter() function proved tricky to wrap and the callback function still takes C style arguments due to the fact that this function is called from the libunit-wasm C library. The provided wrapper simply means we can use this without having to use an unsafe {} block around it in application code. Similarly with other functions that technically didn't need to be wrapped, wrapping them means that the unsafe {} blocks are hidden away. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to '')
-rw-r--r--src/rust/unit-wasm-sys/macros.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/rust/unit-wasm-sys/macros.rs b/src/rust/unit-wasm-sys/macros.rs
index d7fde22..059fef3 100644
--- a/src/rust/unit-wasm-sys/macros.rs
+++ b/src/rust/unit-wasm-sys/macros.rs
@@ -13,3 +13,8 @@ pub const LUW_VERSION_NUMBER: i32 =
(LUW_VERSION_MAJOR << 24) |
(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;