Move out type conversion functionality out of VectorExtern
MODIFY
src/manual/core/vector.rs
src/manual/core/vector.rs
@@ -127,11 +127,16 @@ impl<T: VectorElement> Vector<T> where Self: VectorExtern<T> {
pub fn get(&self, index: size_t) -> Result<T> {
vector_index_check(index, self.len())?;
unsafe { self.extern_get(index) }
+ .into_result()
+ .map(|s| unsafe { T::opencv_from_extern(s) } )
}
/// Same as `get()` but without bounds checking
pub unsafe fn get_unchecked(&self, index: size_t) -> T {
- self.extern_get(index).unwrap() // fixme
+ self.extern_get(index)
+ .into_result()
+ .map(|s| T::opencv_from_extern(s) )
+ .unwrap() // fixme, make it return value directly
}
pub fn iter(&self) -> VectorRefIterator<T> {

MODIFY
src/manual/core/vector/iter.rs
src/manual/core/vector/iter.rs
@@ -15,12 +15,12 @@ impl<T: VectorElement> IntoIterator for Vector<T> where Vector<T>: VectorExtern<
}
}
-impl<'i, T: VectorElement> IntoIterator for &'i Vector<T> where Vector<T>: VectorExtern<T> {
+impl<'v, T: VectorElement> IntoIterator for &'v Vector<T> where Vector<T>: VectorExtern<T> {
type Item = T;
- type IntoIter = VectorRefIterator<'i, T>;
+ type IntoIter = VectorRefIterator<'v, T>;
#[inline]
- fn into_iter(self) -> VectorRefIterator<'i, T> {
+ fn into_iter(self) -> VectorRefIterator<'v, T> {
self.iter()
}
}

MODIFY
src/manual/core/vector/vector_extern.rs
src/manual/core/vector/vector_extern.rs
@@ -3,7 +3,7 @@ use std::ffi::c_void;
use crate::{
core::Vector,
platform_types::size_t,
- Result,
+ sys::Result,
traits::{OpenCVType, OpenCVTypeArg, OpenCVTypeExternContainer},
};
@@ -25,7 +25,7 @@ pub trait VectorExtern<T: for<'a> OpenCVType<'a>> {
#[doc(hidden)] unsafe fn extern_remove(&mut self, index: size_t);
#[doc(hidden)] unsafe fn extern_swap(&mut self, index1: size_t, index2: size_t);
#[doc(hidden)] unsafe fn extern_clear(&mut self);
- #[doc(hidden)] unsafe fn extern_get(&self, index: size_t) -> Result<T>;
+ #[doc(hidden)] unsafe fn extern_get(&self, index: size_t) -> Result<<T as OpenCVType<'_>>::ExternReceive>;
#[doc(hidden)] unsafe fn extern_push<'a>(&mut self, val: <<<T as OpenCVType<'a>>::Arg as OpenCVTypeArg<'a>>::ExternContainer as OpenCVTypeExternContainer>::ExternSend);
#[doc(hidden)] unsafe fn extern_insert<'a>(&mut self, index: size_t, val: <<<T as OpenCVType<'a>>::Arg as OpenCVTypeArg<'a>>::ExternContainer as OpenCVTypeExternContainer>::ExternSend);
#[doc(hidden)] unsafe fn extern_set<'a>(&mut self, index: size_t, val: <<<T as OpenCVType<'a>>::Arg as OpenCVTypeArg<'a>>::ExternContainer as OpenCVTypeExternContainer>::ExternSend);
@@ -121,11 +121,9 @@ macro_rules! vector_extern {
}
#[inline(always)]
- unsafe fn extern_get(&self, index: $crate::platform_types::size_t) -> $crate::Result<$type> {
+ unsafe fn extern_get(&self, index: $crate::platform_types::size_t) -> $crate::sys::Result<<$type as $crate::traits::OpenCVType<'_>>::ExternReceive> {
extern "C" { fn $extern_get<'a>(instance: $vector_extern_const, index: $crate::platform_types::size_t) -> $crate::sys::Result<<$type as $crate::traits::OpenCVType<'a>>::ExternReceive>; }
$extern_get(self.as_raw(), index)
- .into_result()
- .map(|s| <$type>::opencv_from_extern(s))
}
#[inline(always)]

Move out type conversion functionality out of VectorExtern