Reorganize internal traits
MODIFY
binding-generator/tpl/vector/rust.tpl.rs
binding-generator/tpl/vector/rust.tpl.rs
@@ -10,7 +10,7 @@ vector_extern! { {{inner_rust_full}}, {{rust_extern_const}}, {{rust_extern_mut}}
}
{{additional_methods}}
-impl<'i> core::VectorTrait<'i> for {{rust_full}} {
+impl<'i> VectorTrait<'i> for {{rust_full}} {
type Arg = {{inner_rust_full_arg}};
fn with_capacity(capacity: size_t) -> Self { Self::with_capacity(capacity) }

MODIFY
src/lib.rs
src/lib.rs
@@ -10,12 +10,14 @@ mod templ;
mod error;
mod opencv;
mod manual;
+mod traits;
pub mod prelude {
pub use crate::{
core::{DataType, Mat},
hub_prelude::*,
manual::prelude::*,
+ traits::{Boxed, VectorTrait},
};
}
@@ -24,7 +26,7 @@ pub(crate) mod mod_prelude_types {
pub use libc::{clock_t, FILE, ptrdiff_t, size_t};
- pub use crate::core::Boxed;
+ pub use crate::traits::{Boxed, VectorTrait};
}
pub(crate) mod mod_prelude {

MODIFY
src/manual/core.rs
src/manual/core.rs
pub use CV_MAKETYPE as CV_MAKE_TYPE;
pub use affine3::*;
-pub use boxed::*;
pub use input_output_array::*;
pub use mat::*;
pub use matx::*;
@@ -31,7 +30,6 @@ macro_rules! valid_types {
}
mod affine3;
-mod boxed;
mod input_output_array;
mod mat;
mod matx;

MODIFY
src/manual/core/input_output_array.rs
src/manual/core/input_output_array.rs
use std::os::raw::c_void;
use crate::{
- core::{_InputArray, _InputArrayTrait, _InputOutputArray, _InputOutputArrayTrait, _OutputArray, _OutputArrayTrait, Boxed},
+ core::{_InputArray, _InputArrayTrait, _InputOutputArray, _InputOutputArrayTrait, _OutputArray, _OutputArrayTrait},
Result,
sys,
+ traits::Boxed,
};
/// Trait to serve as a replacement for `InputArray` in C++ OpenCV

MODIFY
src/manual/core/matx.rs
src/manual/core/matx.rs
@@ -6,11 +6,12 @@ use std::{
use num_traits::{One, Zero};
use crate::{
- core::{self, Boxed, ToInputArray, ToInputOutputArray, ToOutputArray},
+ core::{self, ToInputArray, ToInputOutputArray, ToOutputArray},
Error,
manual::core::sized::*,
Result,
sys::Result as SysResult,
+ traits::Boxed,
};
fn index_check(idx: (usize, usize), rows: usize, cols: usize) -> Result<()> {

MODIFY
src/manual/core/ptr.rs
src/manual/core/ptr.rs
@@ -6,7 +6,7 @@ use std::{
pub use ptr_extern::PtrExtern;
-use crate::core::Boxed;
+use crate::traits::Boxed;
#[cfg(not(feature = "opencv-32"))]
mod ptr_f32;

MODIFY
src/manual/core/ptr/ptr_f32.rs
src/manual/core/ptr/ptr_f32.rs
use std::ffi::c_void;
use std::ops::{Deref, DerefMut};
-use crate::core::{Boxed, Ptr};
+use crate::{
+ core::Ptr,
+ traits::Boxed,
+};
impl Ptr<f32> {
pub fn new(val: f32) -> Self {

MODIFY
src/manual/core/vec.rs
src/manual/core/vec.rs
use std::ffi::c_void;
use crate::{
- core::{_InputArray, Boxed, ToInputArray},
+ core::{_InputArray, ToInputArray},
Result,
sys,
+ traits::Boxed,
};
pub use self::{scalar::ValidScalarType, vec::ValidVecType};

MODIFY
src/manual/core/vector.rs
src/manual/core/vector.rs
@@ -9,7 +9,7 @@ use libc::size_t;
pub use iter::{VectorIterator, VectorRefIterator};
pub use vector_extern::{VectorElement, VectorExtern, VectorExternCopyNonBool};
-use crate::{core::Boxed, Result};
+use crate::{traits::Boxed, Result};
mod vector_extern;
mod iter;
@@ -157,37 +157,6 @@ impl<T: VectorElement> Drop for Vector<T> where Self: VectorExtern<T> {
}
}
-/// Common interface for all C++ vector types generated by the crate
-///
-/// You'll need to import this trait to use any of the C++ vector wrappers, usually imported as
-/// part of the prelude.
-pub trait VectorTrait<'i>: Sized {
- type Arg;
-
- fn with_capacity(capacity: size_t) -> Self;
-
- /// Create a Vector from iterator
- fn from_iter(s: impl IntoIterator<Item=Self::Arg>) -> Self {
- let s = s.into_iter();
- let (lo, hi) = s.size_hint();
- let mut out = Self::with_capacity(hi.unwrap_or(lo));
- s.for_each(|x| out.push(x));
- out
- }
-
- /// Add new element
- fn push(&mut self, val: Self::Arg);
-
- /// Insert a new element at the specified `index`
- fn insert(&mut self, index: size_t, val: Self::Arg) -> crate::Result<()>;
-
- /// Set element at the specified `index`
- fn set(&mut self, index: size_t, val: Self::Arg) -> crate::Result<()>;
-
- /// Same as `set()` but without bounds checking
- unsafe fn set_unchecked(&mut self, index: size_t, val: Self::Arg);
-}
-
#[inline(always)]
pub(crate) fn vector_index_check(index: size_t, len: size_t) -> crate::Result<()> {
if index >= len {

MODIFY
src/manual/features2d.rs
src/manual/features2d.rs
use std::ffi::c_void;
use crate::{
- core::Boxed,
+ traits::Boxed,
features2d::ORB,
Result,
sys,

MODIFY
src/manual/mod.rs
src/manual/mod.rs
@@ -6,7 +6,7 @@ pub mod sys;
pub mod types;
pub mod prelude {
- pub use super::core::{Boxed, MatConstIteratorTraitManual, MatTraitManual, MatxTrait, UMatTraitManual, VectorTrait};
+ pub use super::{core::{MatConstIteratorTraitManual, MatTraitManual, MatxTrait, UMatTraitManual}};
#[cfg(feature = "opencv-32")]
pub use super::core::MatSizeTraitManual;
}

RENAME
src/manual/core/boxed.rs
src/traits/boxed.rs
@@ -26,7 +26,7 @@ pub trait Boxed: Sized {
#[macro_export]
macro_rules! boxed_ptr {
($type: ty) => {
- impl $crate::core::Boxed for $type {
+ impl $crate::traits::Boxed for $type {
#[inline]
unsafe fn from_raw(ptr: *mut std::ffi::c_void) -> Self {
Self { ptr }

ADD
src/traits/mod.rs
+pub use boxed::*;
+pub use vector::*;
+
+mod boxed;
+mod vector;

ADD
src/traits/vector.rs
+use libc::size_t;
+
+/// Common interface for all C++ vector types generated by the crate
+///
+/// You'll need to import this trait to use any of the C++ vector wrappers, usually imported as
+/// part of the prelude.
+pub trait VectorTrait<'i>: Sized {
+ type Arg;
+
+ fn with_capacity(capacity: size_t) -> Self;
+
+ /// Create a Vector from iterator
+ fn from_iter(s: impl IntoIterator<Item=Self::Arg>) -> Self {
+ let s = s.into_iter();
+ let (lo, hi) = s.size_hint();
+ let mut out = Self::with_capacity(hi.unwrap_or(lo));
+ s.for_each(|x| out.push(x));
+ out
+ }
+
+ /// Add new element
+ fn push(&mut self, val: Self::Arg);
+
+ /// Insert a new element at the specified `index`
+ fn insert(&mut self, index: size_t, val: Self::Arg) -> crate::Result<()>;
+
+ /// Set element at the specified `index`
+ fn set(&mut self, index: size_t, val: Self::Arg) -> crate::Result<()>;
+
+ /// Same as `set()` but without bounds checking
+ unsafe fn set_unchecked(&mut self, index: size_t, val: Self::Arg);
+}

Reorganize internal traits