Skip to main content

host_fn

Attribute Macro host_fn 

Source
#[host_fn]
Expand description

#[host_fn] attribute macro โ€” eliminates unsafe C ABI plumbing from host functions.

Write a normal Rust function using SDK types (HostStr, JsStr, JsStrField). The macro generates the unsafe extern "C" wrapper with correct C ABI signature.

ยงExample

โ“˜
use js2rust_bridge::sdk::{HostStr, JsStr};

#[host_fn]
fn host_concat(s1: HostStr, s2: HostStr) -> JsStr {
    JsStr::new(&format!("{}{}", &s1, &s2))
}