Skip to main content

return_success

Function return_success 

Source
pub unsafe fn return_success(
    data: Value,
    result_buf: *mut *mut u8,
    result_len: *mut usize,
) -> i32
Expand description

Return a success result to the framework

This handles all the unsafe memory management details:

  • Converts the value to JSON
  • Allocates a buffer
  • Shrinks to minimize memory usage
  • Returns the pointer and capacity to the framework

§Safety

The caller must ensure that:

  • result_buf points to valid, properly aligned memory for writing a pointer
  • result_len points to valid, properly aligned memory for writing a usize
  • These pointers remain valid for the duration of the call
  • The pointers are not aliased (no other mutable references exist)

§Example

unsafe {
    let result = json!({"status": "ok"});
    return return_success(result, result_buf, result_len);
}