Add Debug impl to Vector<bool> and add Clone impl
MODIFY
binding-generator/src/writer/rust_native/tpl/vector/cpp.tpl.cpp
binding-generator/src/writer/rust_native/tpl/vector/cpp.tpl.cpp
@@ -7,6 +7,10 @@ extern "C" {
return new {{cpp_full}}();
}
+ {{cpp_extern_return}} cv_{{rust_localalias}}_clone(const {{cpp_full}}* instance) {
+ return new {{cpp_full}}(*instance);
+ }
+
size_t cv_{{rust_localalias}}_len(const {{cpp_full}}* instance) {
return instance->size();
}

MODIFY
binding-generator/src/writer/rust_native/tpl/vector/rust.tpl.rs
binding-generator/src/writer/rust_native/tpl/vector/rust.tpl.rs
{{alias}}
vector_extern! { {{inner_rust_full}}, {{rust_extern_const}}, {{rust_extern_mut}},
- cv_{{rust_localalias}}_new, cv_{{rust_localalias}}_delete,
+ cv_{{rust_localalias}}_new, cv_{{rust_localalias}}_clone, cv_{{rust_localalias}}_delete,
cv_{{rust_localalias}}_len, cv_{{rust_localalias}}_is_empty,
cv_{{rust_localalias}}_capacity, cv_{{rust_localalias}}_shrink_to_fit,
cv_{{rust_localalias}}_reserve, cv_{{rust_localalias}}_remove,

MODIFY
src/manual/core/vector.rs
src/manual/core/vector.rs
@@ -87,10 +87,10 @@ impl<T: VectorElement> OpenCVTypeExternContainer for Vector<T> where Self: Vecto
}
// technically VectorExternCopyNonBool isn't needed but it simplifies this impl
-impl<T: VectorElement + fmt::Debug> fmt::Debug for Vector<T> where Vector<T>: VectorExtern<T> + VectorExternCopyNonBool<T> {
+impl<T: VectorElement + fmt::Debug> fmt::Debug for Vector<T> where Vector<T>: VectorExtern<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.as_slice().fmt(f)
+ f.debug_list().entries(self.iter()).finish()
}
}
@@ -122,6 +122,14 @@ impl<T: VectorElement> Default for Vector<T> where Vector<T>: VectorExtern<T> {
}
}
+
+impl<T: VectorElement> Clone for Vector<T> where Vector<T>: VectorExtern<T> {
+ #[inline]
+ fn clone(&self) -> Vector<T> {
+ self.clone()
+ }
+}
+
impl<'a, T: VectorElement> Extend<<T as OpenCVType<'a>>::Arg> for Vector<T> where Vector<T>: VectorExtern<T> {
fn extend<I: IntoIterator<Item=<T as OpenCVType<'a>>::Arg>>(&mut self, s: I) {
let s = s.into_iter();
@@ -147,6 +155,10 @@ impl<T: VectorElement> Vector<T> where Self: VectorExtern<T> {
unsafe { Self::from_raw(Self::extern_new()) }
}
+ fn clone(&self) -> Vector<T> {
+ unsafe { Self::from_raw(self.extern_clone()) }
+ }
+
/// Create a Vector with pre-defined capacity
pub fn with_capacity(capacity: size_t) -> Self {
let mut out = Self::new();

MODIFY
src/manual/core/vector/vector_extern.rs
src/manual/core/vector/vector_extern.rs
@@ -15,6 +15,7 @@ pub trait VectorElement: Sized + for<'a> OpenCVType<'a> where Vector<Self>: Vect
#[doc(hidden)]
pub trait VectorExtern<T: for<'a> OpenCVType<'a>> {
unsafe fn extern_new() -> *mut c_void;
+ unsafe fn extern_clone(&self) -> *mut c_void;
unsafe fn extern_delete(&mut self);
unsafe fn extern_len(&self) -> size_t;
unsafe fn extern_is_empty(&self) -> bool;
@@ -37,6 +38,7 @@ macro_rules! vector_extern {
$vector_extern_const: ty,
$vector_extern_mut: ty,
$extern_new: ident,
+ $extern_clone: ident,
$extern_delete: ident,
$extern_len: ident,
$extern_is_empty: ident,
@@ -58,6 +60,12 @@ macro_rules! vector_extern {
$extern_new()
}
+ #[inline(always)]
+ unsafe fn extern_clone(&self) -> $vector_extern_mut {
+ extern "C" { fn $extern_clone(instance: $vector_extern_const) -> $vector_extern_mut; }
+ $extern_clone(self.as_raw())
+ }
+
#[inline(always)]
unsafe fn extern_delete(&mut self) {
extern "C" { fn $extern_delete(instance: $vector_extern_mut); }

Add Debug impl to Vector<bool> and add Clone impl