Add const bitcopy constructor for Vec
diff --git a/gen/write.rs b/gen/write.rs
index 8fc698c..ccd6c2f 100644
--- a/gen/write.rs
+++ b/gen/write.rs
@@ -186,7 +186,11 @@
needs_trycatch = true;
}
for arg in &efn.args {
- if arg.ty == RustString {
+ let bitcopy = match arg.ty {
+ Type::RustVec(_) => true,
+ _ => arg.ty == RustString,
+ };
+ if bitcopy {
needs_unsafe_bitcopy = true;
break;
}
@@ -389,6 +393,8 @@
}
if arg.ty == RustString {
write!(out, "const ");
+ } else if let Type::RustVec(_) = arg.ty {
+ write!(out, "const ");
}
write_extern_arg(out, arg, types);
}
@@ -467,6 +473,9 @@
"::rust::String(::rust::unsafe_bitcopy, *{})",
arg.ident,
);
+ } else if let Type::RustVec(_) = arg.ty {
+ write_type(out, &arg.ty);
+ write!(out, "(::rust::unsafe_bitcopy, *{})", arg.ident);
} else if types.needs_indirect_abi(&arg.ty) {
out.include.utility = true;
write!(out, "::std::move(*{})", arg.ident);
diff --git a/include/cxx.h b/include/cxx.h
index e16d9e0..3dc1c4d 100644
--- a/include/cxx.h
+++ b/include/cxx.h
@@ -15,7 +15,13 @@
namespace rust {
inline namespace cxxbridge02 {
-struct unsafe_bitcopy_t;
+#ifndef CXXBRIDGE02_RUST_BITCOPY
+#define CXXBRIDGE02_RUST_BITCOPY
+struct unsafe_bitcopy_t {
+ explicit unsafe_bitcopy_t() = default;
+};
+constexpr unsafe_bitcopy_t unsafe_bitcopy{};
+#endif // CXXBRIDGE02_RUST_BITCOPY
#ifndef CXXBRIDGE02_RUST_STRING
#define CXXBRIDGE02_RUST_STRING
@@ -249,6 +255,9 @@
return it;
}
+ // Internal API only intended for the cxxbridge code generator.
+ Vec(unsafe_bitcopy_t, const Vec &bits) noexcept : repr(bits.repr) {}
+
private:
static size_t stride() noexcept;
void drop() noexcept;
@@ -316,14 +325,6 @@
template <typename Signature>
using try_fn = TryFn<Signature>;
-#ifndef CXXBRIDGE02_RUST_BITCOPY
-#define CXXBRIDGE02_RUST_BITCOPY
-struct unsafe_bitcopy_t {
- explicit unsafe_bitcopy_t() = default;
-};
-constexpr unsafe_bitcopy_t unsafe_bitcopy{};
-#endif // CXXBRIDGE02_RUST_BITCOPY
-
template <typename Ret, typename... Args, bool Throws>
Ret Fn<Ret(Args...), Throws>::operator()(Args... args) const noexcept(!Throws) {
return (*this->trampoline)(std::move(args)..., this->fn);
diff --git a/macro/src/expand.rs b/macro/src/expand.rs
index e0f3cc7..af404d0 100644
--- a/macro/src/expand.rs
+++ b/macro/src/expand.rs
@@ -146,6 +146,8 @@
let ty = expand_extern_type(&arg.ty);
if arg.ty == RustString {
quote!(#ident: *const #ty)
+ } else if let Type::RustVec(_) = arg.ty {
+ quote!(#ident: *const #ty)
} else if let Type::Fn(_) = arg.ty {
quote!(#ident: ::cxx::private::FatFunction)
} else if types.needs_indirect_abi(&arg.ty) {
@@ -207,7 +209,7 @@
}
Type::RustBox(_) => quote!(::std::boxed::Box::into_raw(#var)),
Type::UniquePtr(_) => quote!(::cxx::UniquePtr::into_raw(#var)),
- Type::RustVec(_) => quote!(#var.as_mut_ptr() as *mut ::cxx::private::RustVec<_>),
+ Type::RustVec(_) => quote!(#var.as_mut_ptr() as *const ::cxx::private::RustVec<_>),
Type::Ref(ty) => match &ty.inner {
Type::Ident(ident) if ident == RustString => {
quote!(::cxx::private::RustString::from_ref(#var))