Improve Tuple generation
MODIFY
binding-generator/src/writer/rust_native/tpl/tuple/rust.tpl.rs
binding-generator/src/writer/rust_native/tpl/tuple/rust.tpl.rs
pub type {{rust_localalias}} = {{rust_full}};
-impl {{rust_localalias}} {
- pub fn as_raw_{{rust_localalias}}(&self) -> {{rust_extern_const}} { self.as_raw() }
- pub fn as_raw_mut_{{rust_localalias}}(&mut self) -> {{rust_extern_mut}} { self.as_raw_mut() }
+impl {{rust_full}} {
+ pub fn as_raw_{{rust_localalias}}(&self) -> extern_send!(Self) { self.as_raw() }
+ pub fn as_raw_mut_{{rust_localalias}}(&mut self) -> extern_send!(mut Self) { self.as_raw_mut() }
}
-tuple_extern! { {{inner_rust_full}}, {{rust_extern_const}}, {{rust_extern_mut}},
+tuple_extern! { {{inner_rust_full}},
cv_{{rust_localalias}}_new, cv_{{rust_localalias}}_delete,
{{getters}}
}

MODIFY
binding-generator/src/writer/rust_native/tuple.rs
binding-generator/src/writer/rust_native/tuple.rs
use maplit::hashmap;
use once_cell::sync::Lazy;
-use crate::type_ref::{Constness, ConstnessOverride, ExternDir};
+use crate::type_ref::Constness;
use crate::writer::rust_native::func::disambiguate_single_name;
use crate::writer::rust_native::func_desc::{ClassDesc, CppFuncDesc, FuncDescCppCall, FuncDescKind};
use crate::{CompiledInterpolation, CppNameStyle, Element, FunctionTypeHint, IteratorExt, NameStyle, StrExt, Tuple, TypeRef};
@@ -16,8 +16,6 @@ impl RustNativeGeneratedElement for Tuple<'_, '_> {
fn gen_rust(&self, _opencv_version: &str) -> String {
static RUST_TPL: Lazy<CompiledInterpolation> = Lazy::new(|| include_str!("tpl/tuple/rust.tpl.rs").compile_interpolation());
- let tuple_type = self.type_ref();
-
let rust_localalias = self.rust_localalias();
let mut rets = disambiguate_single_name("arg");
@@ -29,13 +27,11 @@ impl RustNativeGeneratedElement for Tuple<'_, '_> {
.map(|(i, typ)| {
let ret_name = rets.next().expect("Endless iterator");
format!(
- "{ret_name}: {extern_type_mut} = {num}, cv_{alias}_get_{num}: {extern_return} => get_{num}: {typ}",
- ret_name = ret_name,
- extern_type_mut = typ.rust_extern(ExternDir::ToCpp(ConstnessOverride::Mut)),
- alias = rust_localalias,
+ "{num} = {ret_name}: {typ}, get_{num} via cv_{alias}_get_{num}",
num = i,
+ ret_name = ret_name,
typ = typ.rust_name(NameStyle::ref_()),
- extern_return = typ.rust_extern(ExternDir::FromCpp)
+ alias = rust_localalias,
)
})
.join(",\n");
@@ -43,8 +39,6 @@ impl RustNativeGeneratedElement for Tuple<'_, '_> {
RUST_TPL.interpolate(&hashmap! {
"rust_localalias" => rust_localalias,
"rust_full" => self.rust_name(NameStyle::ref_()),
- "rust_extern_const" => tuple_type.rust_extern(ExternDir::ToCpp(ConstnessOverride::Const)),
- "rust_extern_mut" => tuple_type.rust_extern(ExternDir::ToCpp(ConstnessOverride::Mut)),
"inner_rust_full" => self.rust_inner().into(),
"getters" => getters.into(),
})

MODIFY
src/manual/core/tuple.rs
src/manual/core/tuple.rs
@@ -61,7 +61,7 @@ where
}
}
-impl<T> OpenCVTypeExternContainer for Tuple<T>
+impl<T> OpenCVTypeExternContainer<'_> for Tuple<T>
where
Tuple<T>: TupleExtern<T>,
{
@@ -102,27 +102,25 @@ pub trait TupleExtern<T> {
macro_rules! tuple_extern {
(
$type: ty,
- $extern_const: ty,
- $extern_mut: ty,
$extern_new: ident, $extern_delete: ident,
- $($arg: ident: $extern_element_type: ty = $num: tt, $extern_element_get: ident: $extern_element_return: ty => $element_get: ident: $element_type: ty),+
+ $($num: tt = $arg: ident: $element_type: ty, $element_get: ident via $extern_element_get: ident),+
) => {
extern "C" {
- fn $extern_new($( $arg: $extern_element_type ),+) -> $extern_mut;
- fn $extern_delete(instance: $extern_mut);
+ fn $extern_new<'a>($( $arg: extern_arg_send!($element_type: 'a) ),+) -> extern_receive!($crate::core::Tuple<$type>: 'a);
+ fn $extern_delete(instance: extern_send!(mut $crate::core::Tuple<$type>));
$(
- fn $extern_element_get(instance: $extern_const, ocvrs_return: *mut <$extern_element_return as $crate::traits::OpenCVType<'_>>::ExternReceive);
+ fn $extern_element_get(instance: extern_send!($crate::core::Tuple<$type>), ocvrs_return: *mut extern_receive!($element_type));
)+
}
- impl $crate::manual::core::TupleExtern<$type> for $crate::manual::core::Tuple<$type> {
+ impl $crate::core::TupleExtern<$type> for $crate::core::Tuple<$type> {
#[inline]
unsafe fn extern_delete(&mut self) {
$extern_delete(self.as_raw_mut())
}
}
- impl $crate::manual::core::Tuple<$type> {
+ impl $crate::core::Tuple<$type> {
$(
#[inline]
pub fn $element_get(&self) -> $element_type {

Improve Tuple generation