sensorial-systems / ligen

Apache License 2.0
19 stars 3 forks source link

Reference and mutable reference marshalling #10

Open notdanilo opened 3 years ago

notdanilo commented 3 years ago
#[ligen(C)]
fn f(data: &mut [u8]) { ... }

generates this

extern "C" fn c_f(data: &mut [u8]) {
  f(data);
}

because C and Rust are ABI compatible.

#[ligen(C)]
fn f(string: &mut String) { ... }

generates something like this

extern "C" fn c_f(string: mut CString) {
  let mut rust_string = string.to_string();
  f(&mut rust_string);
  string = rust_string.to_cstring();
}

Because marshalling for Strings is necessary.