Make passing String by value to C++ const
diff --git a/gen/write.rs b/gen/write.rs
index e6fb4e9..33898ce 100644
--- a/gen/write.rs
+++ b/gen/write.rs
@@ -169,6 +169,9 @@
if i > 0 {
write!(out, ", ");
}
+ if arg.ty == RustString {
+ write!(out, "const ");
+ }
write_extern_arg(out, arg, types);
}
if indirect_return {
@@ -213,6 +216,8 @@
} else if let Type::UniquePtr(_) = &arg.ty {
write_type(out, &arg.ty);
write!(out, "({})", arg.ident);
+ } else if arg.ty == RustString {
+ write!(out, "::rust::String(::rust::unsafe_bitcopy, *{})", arg.ident);
} else if types.needs_indirect_abi(&arg.ty) {
write!(out, "::std::move(*{})", arg.ident);
} else {
diff --git a/macro/src/expand.rs b/macro/src/expand.rs
index 1237892..9ebb623 100644
--- a/macro/src/expand.rs
+++ b/macro/src/expand.rs
@@ -126,7 +126,9 @@
let args = efn.args.iter().map(|arg| {
let ident = &arg.ident;
let ty = expand_extern_type(&arg.ty);
- if types.needs_indirect_abi(&arg.ty) {
+ if arg.ty == RustString {
+ quote!(#ident: *const #ty)
+ } else if types.needs_indirect_abi(&arg.ty) {
quote!(#ident: *mut #ty)
} else {
quote!(#ident: #ty)
@@ -157,7 +159,7 @@
let var = &arg.ident;
match &arg.ty {
Type::Ident(ident) if ident == RustString => {
- quote!(#var.as_mut_ptr() as *mut ::cxx::private::RustString)
+ quote!(#var.as_mut_ptr() as *const ::cxx::private::RustString)
}
Type::RustBox(_) => quote!(::std::boxed::Box::into_raw(#var)),
Type::UniquePtr(_) => quote!(::cxx::UniquePtr::into_raw(#var)),