ffi_string_owned

Function ffi_string_owned 

Source
pub unsafe fn ffi_string_owned<F>(ffi_call: F) -> Option<String>
where F: FnOnce() -> *mut i8,
Expand description

Retrieves a string from an FFI function that returns an owned C string pointer.

This is more efficient than buffer-based retrieval as it avoids pre-allocation. The FFI function allocates the string (via strdup) and this function takes ownership and frees it.

§Arguments

  • ffi_call - A closure that returns an owned C string pointer (or null)

§Returns

  • Some(String) if the pointer was non-null and valid UTF-8
  • None if the pointer was null

§Safety

The caller must ensure the returned pointer was allocated by Swift’s strdup or equivalent, and that sc_free_string properly frees it.