Add construction and assignment for rust::Vec
diff --git a/src/cxx.cc b/src/cxx.cc
index 63b2166..7465f56 100644
--- a/src/cxx.cc
+++ b/src/cxx.cc
@@ -237,6 +237,8 @@
}
#define RUST_VEC_EXTERNS(RUST_TYPE, CXX_TYPE) \
+ void cxxbridge02$rust_vec$##RUST_TYPE##$new( \
+ rust::Vec<CXX_TYPE> *ptr) noexcept; \
void cxxbridge02$rust_vec$##RUST_TYPE##$drop( \
rust::Vec<CXX_TYPE> *ptr) noexcept; \
size_t cxxbridge02$rust_vec$##RUST_TYPE##$len( \
@@ -247,6 +249,10 @@
#define RUST_VEC_OPS(RUST_TYPE, CXX_TYPE) \
template <> \
+ rust::Vec<CXX_TYPE>::Vec() noexcept { \
+ cxxbridge02$rust_vec$##RUST_TYPE##$new(this); \
+ } \
+ template <> \
void rust::Vec<CXX_TYPE>::drop() noexcept { \
return cxxbridge02$rust_vec$##RUST_TYPE##$drop(this); \
} \
diff --git a/src/rust_vec.rs b/src/rust_vec.rs
index 564851e..d5de489 100644
--- a/src/rust_vec.rs
+++ b/src/rust_vec.rs
@@ -7,6 +7,10 @@
}
impl<T> RustVec<T> {
+ pub fn new() -> Self {
+ RustVec { repr: Vec::new() }
+ }
+
pub fn from(v: Vec<T>) -> Self {
RustVec { repr: v }
}
@@ -43,6 +47,12 @@
const _: () = {
attr! {
+ #[export_name = concat!("cxxbridge02$rust_vec$", stringify!($ty), "$new")]
+ unsafe extern "C" fn __new(this: *mut RustVec<$ty>) {
+ ptr::write(this, RustVec::new());
+ }
+ }
+ attr! {
#[export_name = concat!("cxxbridge02$rust_vec$", stringify!($ty), "$drop")]
unsafe extern "C" fn __drop(this: *mut RustVec<$ty>) {
ptr::drop_in_place(this);