Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit 6764e6e

Browse files
committed
examples/rust: Slightly simplify hello-world
There is no need in this case to declare REQUEST_BUF as a global variable. Declaring it local to uwr_request_handler() lets us get rid of the unsafe code blocks. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
1 parent d81bc92 commit 6764e6e

File tree

1 file changed

+3
-4
lines changed
  • examples/rust/hello-world/src

1 file changed

+3
-4
lines changed

examples/rust/hello-world/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88

99
use unit_wasm::rusty::*;
1010

11-
static mut REQUEST_BUF: *mut u8 = std::ptr::null_mut();
12-
1311
#[no_mangle]
1412
pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
1513
let ctx = &mut UWR_CTX_INITIALIZER();
14+
let mut request_buf: *mut u8 = std::ptr::null_mut();
1615

1716
uwr_init_ctx(ctx, addr, 4096);
18-
uwr_set_req_buf(ctx, unsafe { &mut REQUEST_BUF }, LUW_SRB_ALLOC);
17+
uwr_set_req_buf(ctx, &mut request_buf, LUW_SRB_ALLOC);
1918

2019
uwr_write_str!(
2120
ctx,
@@ -35,7 +34,7 @@ pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
3534
uwr_http_send_response(ctx);
3635
uwr_http_response_end();
3736

38-
uwr_free(unsafe { REQUEST_BUF });
37+
uwr_free(request_buf);
3938

4039
return 0;
4140
}

0 commit comments

Comments
 (0)