Drop separate helper macros for input/output array
MODIFY
binding-generator/src/writer/rust_native/type_ref.rs
binding-generator/src/writer/rust_native/type_ref.rs
@@ -200,12 +200,8 @@ impl<'tu, 'ge> TypeRefExt for TypeRef<'tu, 'ge> {
format!("string_arg_output_send!(via {name}_via)")
}
};
- } else if self.is_input_array() {
- return format!("input_array_arg!({name})");
- } else if self.is_output_array() {
- return format!("output_array_arg!({name})");
- } else if self.is_input_output_array() {
- return format!("input_output_array_arg!({name})");
+ } else if self.is_input_array() || self.is_output_array() || self.is_input_output_array() {
+ return format!("extern_container_arg!({name})");
} else if self.as_string_array().is_some() {
return if self.constness().is_const() {
format!("string_array_arg!({name})")

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};
-use crate::traits::Boxed;
+use crate::traits::{Boxed, OpenCVTypeArg};
use crate::{input_output_array, sys, Result};
/// Trait to serve as a replacement for `InputArray` in C++ OpenCV
@@ -49,6 +49,20 @@ impl<T: _InputArrayTrait> ToInputArray for T {
}
}
+impl OpenCVTypeArg<'_> for &dyn ToInputArray {
+ type ExternContainer = _InputArray;
+
+ #[inline]
+ fn opencv_into_extern_container(self) -> Result<Self::ExternContainer> {
+ self.input_array()
+ }
+
+ #[inline]
+ fn opencv_into_extern_container_nofail(self) -> Self::ExternContainer {
+ self.opencv_into_extern_container().expect("Can't convert to InputArray")
+ }
+}
+
impl<T: _OutputArrayTrait> ToOutputArray for T {
#[inline]
fn output_array(&mut self) -> Result<_OutputArray> {
@@ -62,6 +76,20 @@ impl<T: _OutputArrayTrait> ToOutputArray for T {
}
}
+impl OpenCVTypeArg<'_> for &mut dyn ToOutputArray {
+ type ExternContainer = _OutputArray;
+
+ #[inline]
+ fn opencv_into_extern_container(self) -> Result<Self::ExternContainer> {
+ self.output_array()
+ }
+
+ #[inline]
+ fn opencv_into_extern_container_nofail(self) -> Self::ExternContainer {
+ self.opencv_into_extern_container().expect("Can't convert to OutputArray")
+ }
+}
+
impl<T: _InputOutputArrayTrait> ToInputOutputArray for T {
#[inline]
fn input_output_array(&mut self) -> Result<_InputOutputArray> {
@@ -75,6 +103,22 @@ impl<T: _InputOutputArrayTrait> ToInputOutputArray for T {
}
}
+impl OpenCVTypeArg<'_> for &mut dyn ToInputOutputArray {
+ type ExternContainer = _InputOutputArray;
+
+ #[inline]
+ fn opencv_into_extern_container(self) -> Result<Self::ExternContainer> {
+ self.input_output_array()
+ }
+
+ #[inline]
+ fn opencv_into_extern_container_nofail(self) -> Self::ExternContainer {
+ self
+ .opencv_into_extern_container()
+ .expect("Can't convert to InputOutputArray")
+ }
+}
+
#[doc(hidden)]
#[macro_export]
macro_rules! input_output_array {

MODIFY
src/templ.rs
src/templ.rs
@@ -64,24 +64,6 @@ macro_rules! userdata_arg {
};
}
-macro_rules! input_array_arg {
- ($name: ident) => {
- let $name = $name.input_array()?;
- };
-}
-
-macro_rules! output_array_arg {
- ($name: ident) => {
- let $name = $name.output_array()?;
- };
-}
-
-macro_rules! input_output_array_arg {
- ($name: ident) => {
- let $name = $name.input_output_array()?;
- };
-}
-
macro_rules! string_array_arg {
($name: ident) => {
let $name = $name.iter().map(|x| x.as_ptr() as _).collect::<::std::vec::Vec<_>>();

Drop separate helper macros for input/output array