#[cxx::bridge(namespace = "cxx_d")]
pub mod bridge {
pub struct Greeting {
pub name: String,
pub count: i32,
}
extern "Rust" {
type RustHandle;
fn rust_greet(name: &str) -> String;
fn make_handle() -> Box<RustHandle>;
fn handle_describe(handle: &RustHandle) -> String;
}
unsafe extern "C++" {
include!("cxx-dlang/include/cxx_d.h");
type DHandle;
fn d_double(x: i32) -> i32;
fn d_make_handle() -> UniquePtr<DHandle>;
fn d_run_callback(cb: fn(&str) -> String, input: &str) -> String;
fn d_identity_bool(x: bool) -> bool;
fn d_add_f64(a: f64, b: f64) -> f64;
fn d_str_len(s: &str) -> usize;
fn d_greeting_count(g: &Greeting) -> i32;
}
}
pub struct RustHandle {
value: String,
}
pub fn rust_greet(name: &str) -> String {
cxx::private::prevent_unwind("rust_greet", || format!("Hello, {}! (count=1)", name))
}
pub fn make_handle() -> Box<RustHandle> {
cxx::private::prevent_unwind("make_handle", || {
Box::new(RustHandle {
value: "rust-handle".to_owned(),
})
})
}
pub fn handle_describe(handle: &RustHandle) -> String {
cxx::private::prevent_unwind("handle_describe", || handle.value.clone())
}