Skip to main content

Module ffi

Module ffi 

Source
Expand description

FFI-safe string types for extern “C” function boundaries.

Rust String and &str are NOT FFI-safe (they have unspecified layout). Use FfiString for passing strings across extern “C” boundaries.

Structs§

FfiBytes
C-compatible byte buffer: pointer + length + capacity. Caller owns the allocation; use ffi_free_bytes to free.
FfiString
C-compatible string representation: pointer + length. Caller owns the allocation; use ffi_free_string to free.

Functions§

ffi_free_bytes
Free an FfiBytes returned from an extern function. Safe to call with null ptr or empty FfiBytes.
ffi_free_string
Free an FfiString returned from an extern function. Safe to call with null ptr or empty FfiString.
ffi_to_string
Convert FfiString to Rust String. The FfiString is consumed (memory is freed as part of this call).
ffi_to_vec
Convert FfiBytes to Rust Vec. The FfiBytes is consumed (memory is freed as part of this call).
string_to_ffi
Convert Rust String to FFI-safe FfiString. Caller must call ffi_free_string on the result when done.
vec_to_ffi
Convert Rust Vec to FFI-safe FfiBytes. Caller must call ffi_free_bytes on the result when done.