Skip to main content

Crate ffi_bridge

Crate ffi_bridge 

Source
Expand description

§ffi-bridge

Memory-safe Go↔Rust FFI boundary helpers.

This crate provides:

  • FfiBuffer — heap-allocated byte buffer with explicit ownership semantics
  • FfiString — UTF-8 string safe for crossing the FFI boundary
  • FfiResult — C-ABI result type conveying either a payload or an error
  • FfiError / FfiErrorCode — rich error taxonomy matching the C header
  • Callback registry — register and invoke named callbacks across the FFI boundary
  • catch_panic — converts Rust panics to FfiResult so they never cross the ABI

§Safety contract

  • All buffers and strings allocated by this crate must be freed by the corresponding ffi_*_free function exported from this crate.
  • Panics are caught at every extern "C" boundary via catch_panic.
  • No Rust type with a Drop impl is allowed to cross the FFI boundary as a value; only repr(C) POD structs may do so.

Re-exports§

pub use callback::callback_count;
pub use callback::ffi_callback_count;
pub use callback::ffi_invoke_callback;
pub use callback::ffi_register_callback;
pub use callback::ffi_unregister_callback;
pub use callback::register_callback;
pub use callback::unregister_callback;
pub use errors::catch_panic;
pub use errors::ffi_result_free;
pub use errors::FfiError;
pub use errors::FfiErrorCode;
pub use errors::FfiResult;
pub use memory::ffi_buffer_alloc;
pub use memory::ffi_buffer_free;
pub use memory::ffi_string_alloc;
pub use memory::ffi_string_free;
pub use memory::FfiBuffer;
pub use memory::FfiString;
pub use bridge::*;
pub use types::*;

Modules§

bridge
bridge — High-level bridge call helpers
callback
callback — Named callback registry
errors
errors — Error taxonomy and FFI result type
memory
memory — FFI-safe heap buffers and strings
types
types — Shared FFI-safe type aliases and helpers