Improve Ptr generation
MODIFY
binding-generator/src/writer/rust_native/smart_ptr.rs
binding-generator/src/writer/rust_native/smart_ptr.rs
@@ -2,7 +2,7 @@ use maplit::hashmap;
use once_cell::sync::Lazy;
use std::borrow::Cow;
-use crate::type_ref::{Constness, ConstnessOverride, CppNameStyle, ExternDir, NameStyle};
+use crate::type_ref::{Constness, ConstnessOverride, CppNameStyle, NameStyle};
use crate::writer::rust_native::func_desc::{ClassDesc, CppFuncDesc, FuncDescCppCall, FuncDescKind};
use crate::{type_ref, CompiledInterpolation, Element, EntityElement, FunctionTypeHint, SmartPtr, StrExt, TypeRef};
@@ -26,14 +26,11 @@ impl RustNativeGeneratedElement for SmartPtr<'_, '_> {
static CTOR_TPL: Lazy<CompiledInterpolation> =
Lazy::new(|| include_str!("tpl/smart_ptr/ctor.tpl.rs").compile_interpolation());
- let type_ref = self.type_ref();
let pointee_type = self.pointee();
let mut inter_vars = hashmap! {
"rust_localalias" => self.rust_localalias(),
"rust_full" => self.rust_name(NameStyle::ref_()),
- "rust_extern_const" => type_ref.rust_extern(ExternDir::ToCpp(ConstnessOverride::Const)),
- "rust_extern_mut" => type_ref.rust_extern(ExternDir::ToCpp(ConstnessOverride::Mut)),
"inner_rust_full" => pointee_type.rust_name(NameStyle::ref_()),
};

MODIFY
binding-generator/src/writer/rust_native/tpl/smart_ptr/base_cast.tpl.rs
binding-generator/src/writer/rust_native/tpl/smart_ptr/base_cast.tpl.rs
-ptr_cast_base! { {{rust_localalias}}, core::Ptr<{{base_rust_full_ref}}>,
- cv_{{rust_localalias}}_to_PtrOf{{base_rust_local}},
-}
+ptr_cast_base! { {{rust_localalias}}, core::Ptr<{{base_rust_full_ref}}>, cv_{{rust_localalias}}_to_PtrOf{{base_rust_local}} }

MODIFY
binding-generator/src/writer/rust_native/tpl/smart_ptr/rust.tpl.rs
binding-generator/src/writer/rust_native/tpl/smart_ptr/rust.tpl.rs
@@ -5,9 +5,9 @@ ptr_extern! { {{inner_rust_full}},
}
{{ctor}}
-impl {{rust_localalias}} {
- #[inline] pub fn as_raw_{{rust_localalias}}(&self) -> {{rust_extern_const}} { self.as_raw() }
- #[inline] pub fn as_raw_mut_{{rust_localalias}}(&mut self) -> {{rust_extern_mut}} { self.as_raw_mut() }
+impl {{rust_full}} {
+ #[inline] pub fn as_raw_{{rust_localalias}}(&self) -> extern_send!(Self) { self.as_raw() }
+ #[inline] pub fn as_raw_mut_{{rust_localalias}}(&mut self) -> extern_send!(mut Self) { self.as_raw_mut() }
}
{{impls}}

MODIFY
binding-generator/src/writer/rust_native/tpl/smart_ptr/trait_raw.tpl.rs
binding-generator/src/writer/rust_native/tpl/smart_ptr/trait_raw.tpl.rs
-impl {{base_const_rust_full}} for {{rust_localalias}} {
- #[inline] fn as_raw_{{base_rust_local}}(&self) -> {{rust_extern_const}} { self.inner_as_raw() }
+impl {{base_const_rust_full}} for {{rust_full}} {
+ #[inline] fn as_raw_{{base_rust_local}}(&self) -> *const c_void { self.inner_as_raw() }
}
-impl {{base_rust_full}} for {{rust_localalias}} {
- #[inline] fn as_raw_mut_{{base_rust_local}}(&mut self) -> {{rust_extern_mut}} { self.inner_as_raw_mut() }
+impl {{base_rust_full}} for {{rust_full}} {
+ #[inline] fn as_raw_mut_{{base_rust_local}}(&mut self) -> *mut c_void { self.inner_as_raw_mut() }
}

MODIFY
src/manual/core/ptr.rs
src/manual/core/ptr.rs
@@ -91,7 +91,7 @@ where
}
}
-impl<T: ?Sized> OpenCVTypeExternContainer for Ptr<T>
+impl<T: ?Sized> OpenCVTypeExternContainer<'_> for Ptr<T>
where
Self: PtrExtern,
{

MODIFY
src/manual/core/ptr/ptr_extern.rs
src/manual/core/ptr/ptr_extern.rs
use std::ffi::c_void;
use crate::traits::{OpenCVType, OpenCVTypeArg, OpenCVTypeExternContainer};
+use crate::{extern_container_send, extern_receive, extern_send};
#[doc(hidden)]
pub trait PtrExtern {
@@ -15,19 +16,21 @@ pub trait PtrExtern {
#[doc(hidden)]
pub trait PtrExternCtor<T: for<'a> OpenCVType<'a>>: Sized {
#[doc(hidden)]
- unsafe fn extern_new(val: <<T as OpenCVTypeArg>::ExternContainer as OpenCVTypeExternContainer>::ExternSendMut) -> *mut c_void;
+ unsafe fn extern_new<'a>(val: extern_container_send!(mut T: 'a)) -> extern_receive!(Self: 'a)
+ where
+ Self: OpenCVType<'a>;
}
#[macro_export]
macro_rules! ptr_extern {
($type: ty, $extern_delete: ident, $extern_inner_as_ptr: ident, $extern_inner_as_ptr_mut: ident $(,)?) => {
extern "C" {
- fn $extern_delete(instance: *mut std::ffi::c_void);
- fn $extern_inner_as_ptr(instance: *const std::ffi::c_void) -> *const std::ffi::c_void;
- fn $extern_inner_as_ptr_mut(instance: *mut std::ffi::c_void) -> *mut std::ffi::c_void;
+ fn $extern_delete(instance: extern_send!(mut $crate::core::Ptr<$type>));
+ fn $extern_inner_as_ptr(instance: extern_send!($crate::core::Ptr<$type>)) -> *const std::ffi::c_void;
+ fn $extern_inner_as_ptr_mut(instance: extern_send!(mut $crate::core::Ptr<$type>)) -> *mut std::ffi::c_void;
}
- impl $crate::manual::core::PtrExtern for $crate::manual::core::Ptr<$type> {
+ impl $crate::core::PtrExtern for $crate::core::Ptr<$type> {
#[inline]
unsafe fn extern_delete(&mut self) {
$extern_delete(self.as_raw_mut())
@@ -48,18 +51,14 @@ macro_rules! ptr_extern {
#[macro_export]
macro_rules! ptr_extern_ctor {
- ($type: ty, $extern_new: ident $(,)?) => {
+ ($type: ty, $extern_new: ident) => {
extern "C" {
- fn $extern_new(
- val: <<$type as $crate::traits::OpenCVTypeArg>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSendMut,
- ) -> *mut std::ffi::c_void;
+ fn $extern_new<'a>(val: extern_container_send!(mut $type: 'a)) -> extern_receive!($crate::core::Ptr<$type>: 'a);
}
- impl $crate::manual::core::PtrExternCtor<$type> for $crate::manual::core::Ptr<$type> {
+ impl $crate::core::PtrExternCtor<$type> for $crate::core::Ptr<$type> {
#[inline]
- unsafe fn extern_new(
- val: <<$type as $crate::traits::OpenCVTypeArg>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSendMut,
- ) -> *mut std::ffi::c_void {
+ unsafe fn extern_new<'a>(val: extern_container_send!(mut $type: 'a)) -> extern_receive!(Self: 'a) {
$extern_new(val)
}
}
@@ -68,9 +67,9 @@ macro_rules! ptr_extern_ctor {
#[macro_export]
macro_rules! ptr_cast_base {
- ($type: ty, $base: ty, $extern_convert: ident $(,)?) => {
+ ($type: ty, $base: ty, $extern_convert: ident) => {
extern "C" {
- fn $extern_convert(val: *mut std::ffi::c_void) -> *mut std::ffi::c_void;
+ fn $extern_convert<'a>(val: extern_send!(mut $type)) -> extern_receive!($base: 'a);
}
impl ::std::convert::From<$type> for $base {

Improve Ptr generation