From 0805af7261da1f2875844564dd70a700f0279757 Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Thu, 22 Jun 2023 11:12:15 +0100 Subject: [PATCH] cxx-qt-gen: remove wrapper method for C++ -> Rust invokables This then avoids us needing to generate Rust methods with fully qualified types on the Rust side and removes a load of generation. Related to #404 --- .../cxx-qt-gen/src/generator/cpp/invokable.rs | 88 +++++++++++++-- .../src/generator/rust/invokable.rs | 106 ++++-------------- .../cxx-qt-gen/test_outputs/inheritance.cpp | 4 +- crates/cxx-qt-gen/test_outputs/inheritance.h | 5 + crates/cxx-qt-gen/test_outputs/inheritance.rs | 33 +----- crates/cxx-qt-gen/test_outputs/invokables.cpp | 16 +-- crates/cxx-qt-gen/test_outputs/invokables.h | 10 ++ crates/cxx-qt-gen/test_outputs/invokables.rs | 96 +++------------- .../test_outputs/passthrough_and_naming.cpp | 4 +- .../test_outputs/passthrough_and_naming.h | 6 + .../test_outputs/passthrough_and_naming.rs | 18 +-- crates/cxx-qt-gen/test_outputs/signals.cpp | 2 +- crates/cxx-qt-gen/test_outputs/signals.h | 3 + crates/cxx-qt-gen/test_outputs/signals.rs | 9 +- 14 files changed, 164 insertions(+), 236 deletions(-) diff --git a/crates/cxx-qt-gen/src/generator/cpp/invokable.rs b/crates/cxx-qt-gen/src/generator/cpp/invokable.rs index d398e4c16..dceae9702 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/invokable.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/invokable.rs @@ -67,11 +67,11 @@ pub fn generate_cpp_invokables( .collect::>>()?; let body = format!( - "m_rustObj->{ident}({parameter_names})", + "{ident}({parameter_names})", ident = idents.wrapper.cpp, - parameter_names = vec!["*this"] - .into_iter() - .chain(parameters.iter().map(|parameter| parameter.ident.as_str())) + parameter_names = parameters + .iter() + .map(|parameter| parameter.ident.as_str()) .collect::>() .join(", "), ); @@ -140,6 +140,23 @@ pub fn generate_cpp_invokables( }, }, }); + + // Note that we are generating a header to match the extern "Rust" method + // in Rust for our invokable. + // + // CXX generates the source and we just need the matching header. + // + // TODO: will this always be noexcept ? If the return type is Result is this then removed? + generated.private_methods.push(CppFragment::Header(format!( + "{return_cxx_ty} {ident}({parameter_types}){is_const} noexcept;", + return_cxx_ty = if let Some(return_cxx_ty) = &return_cxx_ty { + return_cxx_ty.as_cxx_ty() + } else { + "void" + }, + ident = idents.wrapper.cpp, + parameter_types = parameter_types, + ))); } Ok(generated) @@ -234,7 +251,7 @@ mod tests { MyObject::voidInvokable() const { // ::std::lock_guard - m_rustObj->voidInvokableWrapper(*this); + voidInvokableWrapper(); } "#} ); @@ -255,7 +272,7 @@ mod tests { MyObject::trivialInvokable(::std::int32_t param) const { // ::std::lock_guard - return m_rustObj->trivialInvokableWrapper(*this, param); + return trivialInvokableWrapper(param); } "#} ); @@ -276,7 +293,7 @@ mod tests { MyObject::opaqueInvokable(QColor const& param) { // ::std::lock_guard - return m_rustObj->opaqueInvokableWrapper(*this, param); + return opaqueInvokableWrapper(param); } "#} ); @@ -297,10 +314,50 @@ mod tests { MyObject::specifiersInvokable(::std::int32_t param) const { // ::std::lock_guard - return m_rustObj->specifiersInvokableWrapper(*this, param); + return specifiersInvokableWrapper(param); } "#} ); + + // private methods + assert_eq!(generated.private_methods.len(), 4); + + let header = if let CppFragment::Header(header) = &generated.private_methods[0] { + header + } else { + panic!("Expected header") + }; + assert_str_eq!(header, "void voidInvokableWrapper() const noexcept;"); + + let header = if let CppFragment::Header(header) = &generated.private_methods[1] { + header + } else { + panic!("Expected header") + }; + assert_str_eq!( + header, + "::std::int32_t trivialInvokableWrapper(::std::int32_t param) const noexcept;" + ); + + let header = if let CppFragment::Header(header) = &generated.private_methods[2] { + header + } else { + panic!("Expected header") + }; + assert_str_eq!( + header, + "::std::unique_ptr opaqueInvokableWrapper(QColor const& param) noexcept;" + ); + + let header = if let CppFragment::Header(header) = &generated.private_methods[3] { + header + } else { + panic!("Expected header") + }; + assert_str_eq!( + header, + "::std::int32_t specifiersInvokableWrapper(::std::int32_t param) const noexcept;" + ); } #[test] @@ -350,9 +407,22 @@ mod tests { MyObject::trivialInvokable(A1 param) const { // ::std::lock_guard - return m_rustObj->trivialInvokableWrapper(*this, param); + return trivialInvokableWrapper(param); } "#} ); + + // private methods + assert_eq!(generated.private_methods.len(), 1); + + let header = if let CppFragment::Header(header) = &generated.private_methods[0] { + header + } else { + panic!("Expected header") + }; + assert_str_eq!( + header, + "B2 trivialInvokableWrapper(A1 param) const noexcept;" + ); } } diff --git a/crates/cxx-qt-gen/src/generator/rust/invokable.rs b/crates/cxx-qt-gen/src/generator/rust/invokable.rs index bbb0461c9..57d117b49 100644 --- a/crates/cxx-qt-gen/src/generator/rust/invokable.rs +++ b/crates/cxx-qt-gen/src/generator/rust/invokable.rs @@ -12,7 +12,7 @@ use crate::{ }; use proc_macro2::TokenStream; use quote::quote; -use syn::{Ident, Result, ReturnType}; +use syn::Result; pub fn generate_rust_invokables( invokables: &Vec, @@ -20,26 +20,21 @@ pub fn generate_rust_invokables( ) -> Result { let mut generated = GeneratedRustQObjectBlocks::default(); let cpp_class_name_rust = &qobject_idents.cpp_class.rust; - let rust_struct_name_rust = &qobject_idents.rust_struct.rust; for invokable in invokables { let idents = QInvokableName::from(invokable); let wrapper_ident_cpp = idents.wrapper.cpp.to_string(); - let wrapper_ident_rust = &idents.wrapper.rust; let invokable_ident_rust = &idents.name.rust; + // TODO: once we aren't using qobject::T in the extern "RustQt" + // we can just pass through the original ExternFn block and add the attribute? let cpp_struct = if invokable.mutable { - quote! { Pin<&mut #cpp_class_name_rust> } + quote! { Pin<&mut #cpp_class_name_rust> } } else { quote! { &#cpp_class_name_rust } }; - let rust_struct = if invokable.mutable { - quote! { &mut #rust_struct_name_rust } - } else { - quote! { &#rust_struct_name_rust } - }; let parameter_signatures = if invokable.parameters.is_empty() { - quote! { self: #rust_struct, cpp: #cpp_struct } + quote! { self: #cpp_struct } } else { let parameters = invokable .parameters @@ -50,14 +45,9 @@ pub fn generate_rust_invokables( quote! { #ident: #ty } }) .collect::>(); - quote! { self: #rust_struct, cpp: #cpp_struct, #(#parameters),* } + quote! { self: #cpp_struct, #(#parameters),* } }; let return_type = &invokable.method.sig.output; - let has_return = if matches!(invokable.method.sig.output, ReturnType::Default) { - quote! {} - } else { - quote! { return } - }; let mut unsafe_block = None; let mut unsafe_call = Some(quote! { unsafe }); @@ -65,31 +55,19 @@ pub fn generate_rust_invokables( std::mem::swap(&mut unsafe_call, &mut unsafe_block); } - let parameter_names = invokable - .parameters - .iter() - .map(|parameter| parameter.ident.clone()) - .collect::>(); - let fragment = RustFragmentPair { cxx_bridge: vec![quote! { - // TODO: is an unsafe block valid? + // Note: extern "Rust" block does not need to be unsafe extern "Rust" { + // Note that we are exposing a Rust method on the C++ type to C++ + // + // CXX ends up generating the source, then we generate the matching header. + #[doc(hidden)] #[cxx_name = #wrapper_ident_cpp] - #unsafe_call fn #wrapper_ident_rust(#parameter_signatures) #return_type; + #unsafe_call fn #invokable_ident_rust(#parameter_signatures) #return_type; } }], - implementation: vec![ - // TODO: not all methods have a wrapper - quote! { - impl #rust_struct_name_rust { - #[doc(hidden)] - pub #unsafe_call fn #wrapper_ident_rust(#parameter_signatures) #return_type { - #has_return cpp.#invokable_ident_rust(#(#parameter_names),*); - } - } - }, - ], + implementation: vec![], }; generated @@ -164,26 +142,16 @@ mod tests { let generated = generate_rust_invokables(&invokables, &qobject_idents).unwrap(); assert_eq!(generated.cxx_mod_contents.len(), 4); - assert_eq!(generated.cxx_qt_mod_contents.len(), 4); + assert_eq!(generated.cxx_qt_mod_contents.len(), 0); // void_invokable assert_tokens_eq( &generated.cxx_mod_contents[0], quote! { extern "Rust" { - #[cxx_name = "voidInvokableWrapper"] - fn void_invokable_wrapper(self: &MyObjectRust, cpp: &MyObject); - } - }, - ); - assert_tokens_eq( - &generated.cxx_qt_mod_contents[0], - quote! { - impl MyObjectRust { #[doc(hidden)] - pub fn void_invokable_wrapper(self: &MyObjectRust, cpp: &MyObject) { - cpp.void_invokable(); - } + #[cxx_name = "voidInvokableWrapper"] + fn void_invokable(self: &MyObject); } }, ); @@ -193,19 +161,9 @@ mod tests { &generated.cxx_mod_contents[1], quote! { extern "Rust" { - #[cxx_name = "trivialInvokableWrapper"] - fn trivial_invokable_wrapper(self: &MyObjectRust, cpp: &MyObject, param: i32) -> i32; - } - }, - ); - assert_tokens_eq( - &generated.cxx_qt_mod_contents[1], - quote! { - impl MyObjectRust { #[doc(hidden)] - pub fn trivial_invokable_wrapper(self: &MyObjectRust, cpp: &MyObject, param: i32) -> i32 { - return cpp.trivial_invokable(param); - } + #[cxx_name = "trivialInvokableWrapper"] + fn trivial_invokable(self: &MyObject, param: i32) -> i32; } }, ); @@ -215,19 +173,9 @@ mod tests { &generated.cxx_mod_contents[2], quote! { extern "Rust" { - #[cxx_name = "opaqueInvokableWrapper"] - fn opaque_invokable_wrapper(self: &mut MyObjectRust, cpp: Pin<&mut MyObject>, param: &QColor) -> UniquePtr; - } - }, - ); - assert_tokens_eq( - &generated.cxx_qt_mod_contents[2], - quote! { - impl MyObjectRust { #[doc(hidden)] - pub fn opaque_invokable_wrapper(self: &mut MyObjectRust, cpp: Pin<&mut MyObject>, param: &QColor) -> UniquePtr { - return cpp.opaque_invokable(param); - } + #[cxx_name = "opaqueInvokableWrapper"] + fn opaque_invokable(self: Pin<&mut MyObject>, param: &QColor) -> UniquePtr; } }, ); @@ -237,19 +185,9 @@ mod tests { &generated.cxx_mod_contents[3], quote! { extern "Rust" { - #[cxx_name = "unsafeInvokableWrapper"] - unsafe fn unsafe_invokable_wrapper(self: &MyObjectRust, cpp: &MyObject, param: *mut T) -> *mut T; - } - }, - ); - assert_tokens_eq( - &generated.cxx_qt_mod_contents[3], - quote! { - impl MyObjectRust { #[doc(hidden)] - pub unsafe fn unsafe_invokable_wrapper(self: &MyObjectRust, cpp: &MyObject, param: *mut T) -> *mut T { - return cpp.unsafe_invokable(param); - } + #[cxx_name = "unsafeInvokableWrapper"] + unsafe fn unsafe_invokable(self:&MyObject, param: *mut T) -> *mut T; } }, ); diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.cpp b/crates/cxx-qt-gen/test_outputs/inheritance.cpp index 39b2994de..ca7e0f10a 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.cpp +++ b/crates/cxx-qt-gen/test_outputs/inheritance.cpp @@ -18,14 +18,14 @@ QVariant MyObject::data(QModelIndex const& _index, ::std::int32_t _role) const { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - return m_rustObj->dataWrapper(*this, _index, _role); + return dataWrapper(_index, _role); } bool MyObject::hasChildren(QModelIndex const& _parent) const { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - return m_rustObj->hasChildrenWrapper(*this, _parent); + return hasChildrenWrapper(_parent); } MyObject::MyObject(QObject* parent) diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.h b/crates/cxx-qt-gen/test_outputs/inheritance.h index 8d1af3977..4e8ec776d 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.h +++ b/crates/cxx-qt-gen/test_outputs/inheritance.h @@ -37,6 +37,11 @@ class MyObject : public QAbstractItemModel } explicit MyObject(QObject* parent = nullptr); +private: + QVariant dataWrapper(QModelIndex const& _index, + ::std::int32_t _role) const noexcept; + bool hasChildrenWrapper(QModelIndex const& _parent) const noexcept; + private: ::rust::Box m_rustObj; ::std::shared_ptr<::std::recursive_mutex> m_rustObjMutex; diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.rs b/crates/cxx-qt-gen/test_outputs/inheritance.rs index 0b5c6d3a7..38e56ced1 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.rs +++ b/crates/cxx-qt-gen/test_outputs/inheritance.rs @@ -35,18 +35,14 @@ mod inheritance { type MyObjectRust; } extern "Rust" { + #[doc(hidden)] #[cxx_name = "dataWrapper"] - fn data_wrapper( - self: &MyObjectRust, - cpp: &MyObject, - _index: &QModelIndex, - _role: i32, - ) -> QVariant; + fn data(self: &MyObject, _index: &QModelIndex, _role: i32) -> QVariant; } extern "Rust" { + #[doc(hidden)] #[cxx_name = "hasChildrenWrapper"] - fn has_children_wrapper(self: &MyObjectRust, cpp: &MyObject, _parent: &QModelIndex) - -> bool; + fn has_children(self: &MyObject, _parent: &QModelIndex) -> bool; } unsafe extern "C++" { #[doc = " Inherited hasChildren from the base class"] @@ -83,27 +79,6 @@ pub mod cxx_qt_inheritance { #[doc(hidden)] type UniquePtr = cxx::UniquePtr; type MyObjectRust = super::MyObjectRust; - impl MyObjectRust { - #[doc(hidden)] - pub fn data_wrapper( - self: &MyObjectRust, - cpp: &MyObject, - _index: &QModelIndex, - _role: i32, - ) -> QVariant { - return cpp.data(_index, _role); - } - } - impl MyObjectRust { - #[doc(hidden)] - pub fn has_children_wrapper( - self: &MyObjectRust, - cpp: &MyObject, - _parent: &QModelIndex, - ) -> bool { - return cpp.has_children(_parent); - } - } impl cxx_qt::Locking for MyObject {} #[doc = r" Generated CXX-Qt method which creates a boxed rust struct of a QObject"] pub fn create_rs_my_object_rust() -> std::boxed::Box { diff --git a/crates/cxx-qt-gen/test_outputs/invokables.cpp b/crates/cxx-qt-gen/test_outputs/invokables.cpp index f3bd13f75..325c3a024 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.cpp +++ b/crates/cxx-qt-gen/test_outputs/invokables.cpp @@ -24,14 +24,14 @@ void MyObject::invokable() const { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - m_rustObj->invokableWrapper(*this); + invokableWrapper(); } void MyObject::invokableMutable() { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - m_rustObj->invokableMutableWrapper(*this); + invokableMutableWrapper(); } void @@ -40,42 +40,42 @@ MyObject::invokableParameters(QColor const& opaque, ::std::int32_t primitive) const { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - m_rustObj->invokableParametersWrapper(*this, opaque, trivial, primitive); + invokableParametersWrapper(opaque, trivial, primitive); } ::std::unique_ptr MyObject::invokableReturnOpaque() { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - return m_rustObj->invokableReturnOpaqueWrapper(*this); + return invokableReturnOpaqueWrapper(); } QPoint MyObject::invokableReturnTrivial() { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - return m_rustObj->invokableReturnTrivialWrapper(*this); + return invokableReturnTrivialWrapper(); } void MyObject::invokableFinal() const { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - m_rustObj->invokableFinalWrapper(*this); + invokableFinalWrapper(); } void MyObject::invokableOverride() const { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - m_rustObj->invokableOverrideWrapper(*this); + invokableOverrideWrapper(); } void MyObject::invokableVirtual() const { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - m_rustObj->invokableVirtualWrapper(*this); + invokableVirtualWrapper(); } static_assert(alignof(MyObjectCxxQtThread) <= alignof(::std::size_t), diff --git a/crates/cxx-qt-gen/test_outputs/invokables.h b/crates/cxx-qt-gen/test_outputs/invokables.h index 8e0077c76..1458d65f0 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.h +++ b/crates/cxx-qt-gen/test_outputs/invokables.h @@ -40,6 +40,16 @@ class MyObject : public QObject explicit MyObject(::std::int32_t arg0, QObject* arg1); private: + void invokableWrapper() const noexcept; + void invokableMutableWrapper() noexcept; + void invokableParametersWrapper(QColor const& opaque, + QPoint const& trivial, + ::std::int32_t primitive) const noexcept; + ::std::unique_ptr invokableReturnOpaqueWrapper() noexcept; + QPoint invokableReturnTrivialWrapper() noexcept; + void invokableFinalWrapper() const noexcept; + void invokableOverrideWrapper() const noexcept; + void invokableVirtualWrapper() const noexcept; explicit MyObject( cxx_qt::my_object::cxx_qt_my_object::CxxQtConstructorArguments0&& args); diff --git a/crates/cxx-qt-gen/test_outputs/invokables.rs b/crates/cxx-qt-gen/test_outputs/invokables.rs index e71f13bbb..158cecba4 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.rs +++ b/crates/cxx-qt-gen/test_outputs/invokables.rs @@ -36,48 +36,44 @@ mod ffi { type MyObjectRust; } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableWrapper"] - fn invokable_wrapper(self: &MyObjectRust, cpp: &MyObject); + fn invokable(self: &MyObject); } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableMutableWrapper"] - fn invokable_mutable_wrapper(self: &mut MyObjectRust, cpp: Pin<&mut MyObject>); + fn invokable_mutable(self: Pin<&mut MyObject>); } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableParametersWrapper"] - fn invokable_parameters_wrapper( - self: &MyObjectRust, - cpp: &MyObject, - opaque: &QColor, - trivial: &QPoint, - primitive: i32, - ); + fn invokable_parameters(self: &MyObject, opaque: &QColor, trivial: &QPoint, primitive: i32); } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableReturnOpaqueWrapper"] - fn invokable_return_opaque_wrapper( - self: &mut MyObjectRust, - cpp: Pin<&mut MyObject>, - ) -> UniquePtr; + fn invokable_return_opaque(self: Pin<&mut MyObject>) -> UniquePtr; } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableReturnTrivialWrapper"] - fn invokable_return_trivial_wrapper( - self: &mut MyObjectRust, - cpp: Pin<&mut MyObject>, - ) -> QPoint; + fn invokable_return_trivial(self: Pin<&mut MyObject>) -> QPoint; } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableFinalWrapper"] - fn invokable_final_wrapper(self: &MyObjectRust, cpp: &MyObject); + fn invokable_final(self: &MyObject); } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableOverrideWrapper"] - fn invokable_override_wrapper(self: &MyObjectRust, cpp: &MyObject); + fn invokable_override(self: &MyObject); } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableVirtualWrapper"] - fn invokable_virtual_wrapper(self: &MyObjectRust, cpp: &MyObject); + fn invokable_virtual(self: &MyObject); } unsafe extern "C++" { #[doc(hidden)] @@ -174,66 +170,6 @@ pub mod cxx_qt_ffi { #[doc(hidden)] type UniquePtr = cxx::UniquePtr; type MyObjectRust = super::MyObjectRust; - impl MyObjectRust { - #[doc(hidden)] - pub fn invokable_wrapper(self: &MyObjectRust, cpp: &MyObject) { - cpp.invokable(); - } - } - impl MyObjectRust { - #[doc(hidden)] - pub fn invokable_mutable_wrapper(self: &mut MyObjectRust, cpp: Pin<&mut MyObject>) { - cpp.invokable_mutable(); - } - } - impl MyObjectRust { - #[doc(hidden)] - pub fn invokable_parameters_wrapper( - self: &MyObjectRust, - cpp: &MyObject, - opaque: &QColor, - trivial: &QPoint, - primitive: i32, - ) { - cpp.invokable_parameters(opaque, trivial, primitive); - } - } - impl MyObjectRust { - #[doc(hidden)] - pub fn invokable_return_opaque_wrapper( - self: &mut MyObjectRust, - cpp: Pin<&mut MyObject>, - ) -> UniquePtr { - return cpp.invokable_return_opaque(); - } - } - impl MyObjectRust { - #[doc(hidden)] - pub fn invokable_return_trivial_wrapper( - self: &mut MyObjectRust, - cpp: Pin<&mut MyObject>, - ) -> QPoint { - return cpp.invokable_return_trivial(); - } - } - impl MyObjectRust { - #[doc(hidden)] - pub fn invokable_final_wrapper(self: &MyObjectRust, cpp: &MyObject) { - cpp.invokable_final(); - } - } - impl MyObjectRust { - #[doc(hidden)] - pub fn invokable_override_wrapper(self: &MyObjectRust, cpp: &MyObject) { - cpp.invokable_override(); - } - } - impl MyObjectRust { - #[doc(hidden)] - pub fn invokable_virtual_wrapper(self: &MyObjectRust, cpp: &MyObject) { - cpp.invokable_virtual(); - } - } impl cxx_qt::Threading for MyObject { type BoxedQueuedFn = MyObjectCxxQtThreadQueuedFn; type ThreadingTypeId = cxx::type_id!("cxx_qt::my_object::MyObjectCxxQtThread"); diff --git a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp index 27a5986f6..b52eafb2b 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp @@ -49,7 +49,7 @@ void MyObject::invokableName() { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - m_rustObj->invokableNameWrapper(*this); + invokableNameWrapper(); } ::QMetaObject::Connection @@ -122,7 +122,7 @@ void SecondObject::invokableName() { - m_rustObj->invokableNameWrapper(*this); + invokableNameWrapper(); } ::QMetaObject::Connection diff --git a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h index c23cfa917..cd3b96b67 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h @@ -45,6 +45,9 @@ class MyObject : public QStringListModel ::Qt::ConnectionType type); explicit MyObject(QObject* parent = nullptr); +private: + void invokableNameWrapper() noexcept; + private: ::rust::Box m_rustObj; ::std::shared_ptr<::std::recursive_mutex> m_rustObjMutex; @@ -81,6 +84,9 @@ class SecondObject : public QObject ::Qt::ConnectionType type); explicit SecondObject(QObject* parent = nullptr); +private: + void invokableNameWrapper() noexcept; + private: ::rust::Box m_rustObj; }; diff --git a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs index a4560cb39..ad717cf80 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs @@ -98,8 +98,9 @@ pub mod ffi { ) -> CxxQtQMetaObjectConnection; } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableNameWrapper"] - fn invokable_name_wrapper(self: &mut MyObjectRust, cpp: Pin<&mut MyObject>); + fn invokable_name(self: Pin<&mut MyObject>); } unsafe extern "C++" { #[rust_name = "ready"] @@ -170,8 +171,9 @@ pub mod ffi { ) -> CxxQtQMetaObjectConnection; } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableNameWrapper"] - fn invokable_name_wrapper(self: &mut SecondObjectRust, cpp: Pin<&mut SecondObject>); + fn invokable_name(self: Pin<&mut SecondObject>); } unsafe extern "C++" { #[my_attribute] @@ -260,12 +262,6 @@ pub mod cxx_qt_ffi { self.connect_property_name_changed(func, CxxQtConnectionType::AutoConnection) } } - impl MyObjectRust { - #[doc(hidden)] - pub fn invokable_name_wrapper(self: &mut MyObjectRust, cpp: Pin<&mut MyObject>) { - cpp.invokable_name(); - } - } impl MyObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"] @@ -345,12 +341,6 @@ pub mod cxx_qt_ffi { self.connect_property_name_changed(func, CxxQtConnectionType::AutoConnection) } } - impl SecondObjectRust { - #[doc(hidden)] - pub fn invokable_name_wrapper(self: &mut SecondObjectRust, cpp: Pin<&mut SecondObject>) { - cpp.invokable_name(); - } - } impl SecondObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"] diff --git a/crates/cxx-qt-gen/test_outputs/signals.cpp b/crates/cxx-qt-gen/test_outputs/signals.cpp index c1b3c9242..ca664eca5 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.cpp +++ b/crates/cxx-qt-gen/test_outputs/signals.cpp @@ -20,7 +20,7 @@ void MyObject::invokable() { const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); - m_rustObj->invokableWrapper(*this); + invokableWrapper(); } ::QMetaObject::Connection diff --git a/crates/cxx-qt-gen/test_outputs/signals.h b/crates/cxx-qt-gen/test_outputs/signals.h index 3d3219b21..c3e66960c 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.h +++ b/crates/cxx-qt-gen/test_outputs/signals.h @@ -50,6 +50,9 @@ class MyObject : public QObject ::Qt::ConnectionType type); explicit MyObject(QObject* parent = nullptr); +private: + void invokableWrapper() noexcept; + private: ::rust::Box m_rustObj; ::std::shared_ptr<::std::recursive_mutex> m_rustObjMutex; diff --git a/crates/cxx-qt-gen/test_outputs/signals.rs b/crates/cxx-qt-gen/test_outputs/signals.rs index 9f4aacce8..e64757f0f 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.rs +++ b/crates/cxx-qt-gen/test_outputs/signals.rs @@ -34,8 +34,9 @@ mod ffi { type MyObjectRust; } extern "Rust" { + #[doc(hidden)] #[cxx_name = "invokableWrapper"] - fn invokable_wrapper(self: &mut MyObjectRust, cpp: Pin<&mut MyObject>); + fn invokable(self: Pin<&mut MyObject>); } unsafe extern "C++" { #[rust_name = "ready"] @@ -134,12 +135,6 @@ pub mod cxx_qt_ffi { #[doc(hidden)] type UniquePtr = cxx::UniquePtr; type MyObjectRust = super::MyObjectRust; - impl MyObjectRust { - #[doc(hidden)] - pub fn invokable_wrapper(self: &mut MyObjectRust, cpp: Pin<&mut MyObject>) { - cpp.invokable(); - } - } impl MyObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"]