I’m not sure that those actually solve kornel’s expressed need. What they talked about was not the C/C++ header needed for manually written extern “C” functions and constants, but:
So I’d love some proc macro that automagically wraps Rust functions like fn foo(x: &str, y: &[i32]) to be exposed as foo(char *, int *, size_t len) to C, and adds a prelude to the function that checks that args are non-NULL, strings are UTF-8, makes slices from pointer + length, etc.
They were referring to Rust-native functions, with safe, validated inputs, that has no idea if its being called across an FFI boundary, and “magic” taken to basically write an extern unsafe function that safely validates inputs from the FFI boundary, and then calls the native function with correctly validated data and types.
Consider this example:
#[arcana]
fn foo(&str)->&str { /*...substring? ... *./ }
Which would result in:
extern "C" {
#[no_mangle]
fn foo(p: *mut u8, len: usize, op: *mut *mut u8) -> usize {
if p.is_null() { panic!(); }
// make str via unsafe means
let s_output = foo_r(us_input);
op = s_output.as_ptr();
let u = s_output.len();
::std::mem::forget(s_output);
return u;
}
}
fn foo(&str)->&str { /*...substring? ... *./ }
Am I wrong, kornel?