Skip to main content

ffi_export

Attribute Macro ffi_export 

Source
#[ffi_export]
Expand description

Attribute macro that takes an async (or sync) Rust function and emits a matching extern "C" shim.

Supported signatures:

#[ffi_export]
pub fn balance(handle: WeyWalletHandle) -> i64 { ... }

#[ffi_export(name = "weby_wallet_open")]
pub async fn open(path: &str) -> Result<WeyWalletHandle, Error> { ... }

Generates:

  • extern "C" fn weby_wallet_balance(handle: WeyWalletHandle) -> i64
  • extern "C" fn weby_wallet_open(path: *const c_char, out: *mut WeyWalletHandle) -> i32 — async wrapped via the FFI runtime; result marshaled to (error_code, out).

The macro recognises a small set of marshaling rules:

  • &str*const c_char (read with CStr::from_ptr)
  • String*const c_char (caller frees nothing; we copy)
  • Result<T, E> → returns i32 with T written via *out ptr
  • Result<(), E> → returns i32
  • i32 / i64 / u32 / u64 / bool / opaque handle types → as-is