Touch up PR 67

This commit is contained in:
David Tolnay 2020-04-25 13:17:27 -07:00
parent 4fcfa945c6
commit 85db5a01b2
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
4 changed files with 20 additions and 19 deletions

View File

@ -1031,7 +1031,7 @@ fn write_rust_vec_impl(out: &mut OutFile, ty: &Type) {
writeln!( writeln!(
out, out,
" return cxxbridge02$rust_vec${}$drop(this);", " return cxxbridge02$rust_vec${}$drop(this);",
instance instance,
); );
writeln!(out, "}}"); writeln!(out, "}}");
@ -1044,7 +1044,7 @@ fn write_rust_vec_impl(out: &mut OutFile, ty: &Type) {
writeln!( writeln!(
out, out,
"Vec<{}>::operator ::std::vector<{}>() const noexcept {{", "Vec<{}>::operator ::std::vector<{}>() const noexcept {{",
inner, inner inner, inner,
); );
writeln!(out, " ::std::vector<{}> v;", inner); writeln!(out, " ::std::vector<{}> v;", inner);
writeln!(out, " v.reserve(this->size());"); writeln!(out, " v.reserve(this->size());");

View File

@ -602,6 +602,7 @@ fn expand_rust_vec(namespace: &Namespace, ty: &Type, ident: &Ident) -> TokenStre
unsafe extern "C" fn #local_vector_from(this: *mut ::cxx::RustVec<#inner>, vector: *mut ::cxx::RealVector<#inner>) { unsafe extern "C" fn #local_vector_from(this: *mut ::cxx::RustVec<#inner>, vector: *mut ::cxx::RealVector<#inner>) {
this.as_ref().unwrap().into_vector(vector.as_mut().unwrap()); this.as_ref().unwrap().into_vector(vector.as_mut().unwrap());
} }
#[doc(hidden)]
#[export_name = #link_len] #[export_name = #link_len]
unsafe extern "C" fn #local_len(this: *const ::cxx::RustVec<#inner>) -> usize { unsafe extern "C" fn #local_len(this: *const ::cxx::RustVec<#inner>) -> usize {
this.as_ref().unwrap().len() this.as_ref().unwrap().len()

View File

@ -71,6 +71,7 @@ impl<'a, T: VectorTarget<T>> IntoIterator for &'a RealVector<T> {
impl<'a, T: VectorTarget<T>> Iterator for VectorIntoIterator<'a, T> { impl<'a, T: VectorTarget<T>> Iterator for VectorIntoIterator<'a, T> {
type Item = &'a T; type Item = &'a T;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.index = self.index + 1; self.index = self.index + 1;
self.v.get(self.index - 1) self.v.get(self.index - 1)

View File

@ -59,29 +59,28 @@ std::unique_ptr<std::string> c_return_unique_ptr_string() {
} }
std::unique_ptr<std::vector<uint8_t>> c_return_unique_ptr_vector_u8() { std::unique_ptr<std::vector<uint8_t>> c_return_unique_ptr_vector_u8() {
auto retval = auto vec = std::unique_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>());
std::unique_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>()); vec->push_back(86);
retval->push_back(86); vec->push_back(75);
retval->push_back(75); vec->push_back(30);
retval->push_back(30); vec->push_back(9);
retval->push_back(9); return vec;
return retval;
} }
std::unique_ptr<std::vector<double>> c_return_unique_ptr_vector_f64() { std::unique_ptr<std::vector<double>> c_return_unique_ptr_vector_f64() {
auto retval = std::unique_ptr<std::vector<double>>(new std::vector<double>()); auto vec = std::unique_ptr<std::vector<double>>(new std::vector<double>());
retval->push_back(86.0); vec->push_back(86.0);
retval->push_back(75.0); vec->push_back(75.0);
retval->push_back(30.0); vec->push_back(30.0);
retval->push_back(9.5); vec->push_back(9.5);
return retval; return vec;
} }
std::unique_ptr<std::vector<Shared>> c_return_unique_ptr_vector_shared() { std::unique_ptr<std::vector<Shared>> c_return_unique_ptr_vector_shared() {
auto retval = std::unique_ptr<std::vector<Shared>>(new std::vector<Shared>()); auto vec = std::unique_ptr<std::vector<Shared>>(new std::vector<Shared>());
retval->push_back(Shared{1010}); vec->push_back(Shared{1010});
retval->push_back(Shared{1011}); vec->push_back(Shared{1011});
return retval; return vec;
} }
void c_take_primitive(size_t n) { void c_take_primitive(size_t n) {