js2rust-bridge 0.1.0

FFI bridge runtime for js2rust-generated Zig code
// js2rust-bridge: Rust FFI bindings for translated JS/Zig code.
//
// AUTO-GENERATED by js2rustc — do not edit manually.
// Each `js2rust_bridge!()` invocation reads cabi_exports.json at compile time
// and generates `unsafe extern "C"` + safe Rust wrappers.

use js2rust_bridge_macro::js2rust_bridge;

pub mod host;

// === Auto-generated FFI bindings for each group ===
js2rust_bridge!("out/main/cabi_exports.json");

// === String conversion helpers ===

/// Convert a null-terminated C string pointer to a Rust &str.
///
/// # Safety
/// The pointer must be a valid, null-terminated C string allocated by Zig.
/// The returned &str borrows the memory; call the corresponding `free_*`
/// function after use to release the memory.
pub unsafe fn cstr_to_str<'a>(ptr: *const std::ffi::c_char) -> Option<&'a str> {
    if ptr.is_null() {
        return None;
    }
    let c_str = unsafe { std::ffi::CStr::from_ptr(ptr) };
    c_str.to_str().ok()
}