Skip to content

Commit e47b8da

Browse files
Add Transitive casting and testing code
1 parent cda393b commit e47b8da

File tree

15 files changed

+361
-58
lines changed

15 files changed

+361
-58
lines changed

crates/cxx-qt-gen/src/generator/rust/fragment.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,17 @@ impl GeneratedRustFragment {
7777
unsafe fn #downcast_fn(base: *const #base_unqualified) -> *const #struct_name_unqualified;
7878
}
7979
}],
80-
cxx_qt_mod_contents: vec![
81-
parse_quote! {
82-
unsafe impl ::cxx_qt::Upcast<#base_qualified> for #struct_name {
83-
unsafe fn upcast_ptr(this: *const Self) -> *const #base_qualified {
84-
#upcast_fn_qualified(this)
85-
}
80+
cxx_qt_mod_contents: vec![parse_quote! {
81+
unsafe impl ::cxx_qt::casting::Upcast<#base_qualified> for #struct_name {
82+
unsafe fn upcast_ptr(this: *const Self) -> *const #base_qualified {
83+
#upcast_fn_qualified(this)
84+
}
8685

87-
unsafe fn from_base_ptr(base: *const #base_qualified) -> *const Self {
88-
#downcast_fn_qualified(base)
89-
}
86+
unsafe fn from_base_ptr(base: *const #base_qualified) -> *const Self {
87+
#downcast_fn_qualified(base)
9088
}
91-
},
92-
// Add back once we figure out the bug with QObject, for automatic transitive casts
93-
// parse_quote! {
94-
// unsafe impl ::cxx_qt::MainCast for #struct_name {
95-
// type Base = #base_qualified;
96-
// }
97-
// }
98-
],
89+
}
90+
}],
9991
})
10092
}
10193

crates/cxx-qt-gen/test_outputs/cfgs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ cxx_qt::static_assertions::assert_eq_size!(
677677
cxx_qt::signalhandler::CxxQtSignalHandler<QObjectEnabledCxxQtSignalClosuresignal_enabled>,
678678
[usize; 2]
679679
);
680-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::QObjectEnabled {
680+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::QObjectEnabled {
681681
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
682682
ffi::cxx_qt_ffi_QObjectEnabled_upcastPtr(this)
683683
}
@@ -864,7 +864,7 @@ cxx_qt::static_assertions::assert_eq_size!(
864864
cxx_qt::signalhandler::CxxQtSignalHandler<QObjectDisabledCxxQtSignalClosuresignal_enabled>,
865865
[usize; 2]
866866
);
867-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::QObjectDisabled {
867+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::QObjectDisabled {
868868
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
869869
ffi::cxx_qt_ffi_QObjectDisabled_upcastPtr(this)
870870
}
@@ -895,7 +895,7 @@ impl ::cxx_qt::CxxQtType for ffi::QObjectDisabled {
895895
ffi::cxx_qt_ffi_QObjectDisabled_unsafeRustMut(self)
896896
}
897897
}
898-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::QObjectExternEnabled {
898+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::QObjectExternEnabled {
899899
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
900900
ffi::cxx_qt_ffi_QObjectExternEnabled_upcastPtr(this)
901901
}
@@ -1073,7 +1073,7 @@ cxx_qt::static_assertions::assert_eq_size!(
10731073
>,
10741074
[usize; 2]
10751075
);
1076-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::QObjectExternDisabled {
1076+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::QObjectExternDisabled {
10771077
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
10781078
ffi::cxx_qt_ffi_QObjectExternDisabled_upcastPtr(this)
10791079
}

crates/cxx-qt-gen/test_outputs/inheritance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ mod inheritance {
130130
type QObject = cxx_qt::QObject;
131131
}
132132
}
133-
unsafe impl ::cxx_qt::Upcast<inheritance::QAbstractItemModel> for inheritance::MyObject {
133+
unsafe impl ::cxx_qt::casting::Upcast<inheritance::QAbstractItemModel> for inheritance::MyObject {
134134
unsafe fn upcast_ptr(this: *const Self) -> *const inheritance::QAbstractItemModel {
135135
inheritance::cxx_qt_ffi_MyObject_upcastPtr(this)
136136
}
@@ -158,15 +158,15 @@ impl ::cxx_qt::CxxQtType for inheritance::MyObject {
158158
inheritance::cxx_qt_ffi_MyObject_unsafeRustMut(self)
159159
}
160160
}
161-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for inheritance::QPushButton {
161+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for inheritance::QPushButton {
162162
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
163163
inheritance::cxx_qt_ffi_QPushButton_upcastPtr(this)
164164
}
165165
unsafe fn from_base_ptr(base: *const ::cxx_qt::QObject) -> *const Self {
166166
inheritance::cxx_qt_ffi_QPushButton_downcastPtr(base)
167167
}
168168
}
169-
unsafe impl ::cxx_qt::Upcast<inheritance::QPushButton> for inheritance::QPushButtonChild {
169+
unsafe impl ::cxx_qt::casting::Upcast<inheritance::QPushButton> for inheritance::QPushButtonChild {
170170
unsafe fn upcast_ptr(this: *const Self) -> *const inheritance::QPushButton {
171171
inheritance::cxx_qt_ffi_QPushButtonChild_upcastPtr(this)
172172
}

crates/cxx-qt-gen/test_outputs/invokables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl cxx_qt::Threading for ffi::MyObject {
326326
pub struct MyObjectCxxQtThreadQueuedFn {
327327
inner: std::boxed::Box<dyn FnOnce(core::pin::Pin<&mut ffi::MyObject>) + Send>,
328328
}
329-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::MyObject {
329+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::MyObject {
330330
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
331331
ffi::cxx_qt_ffi_MyObject_upcastPtr(this)
332332
}

crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ cxx_qt::static_assertions::assert_eq_size!(
659659
cxx_qt::signalhandler::CxxQtSignalHandler<MyObjectCxxQtSignalClosureready>,
660660
[usize; 2]
661661
);
662-
unsafe impl ::cxx_qt::Upcast<ffi::QStringListModel> for ffi::MyObject {
662+
unsafe impl ::cxx_qt::casting::Upcast<ffi::QStringListModel> for ffi::MyObject {
663663
unsafe fn upcast_ptr(this: *const Self) -> *const ffi::QStringListModel {
664664
ffi::cxx_qt_ffi_MyObject_upcastPtr(this)
665665
}
@@ -839,7 +839,7 @@ cxx_qt::static_assertions::assert_eq_size!(
839839
cxx_qt::signalhandler::CxxQtSignalHandler<SecondObjectCxxQtSignalClosureready>,
840840
[usize; 2]
841841
);
842-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::SecondObject {
842+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::SecondObject {
843843
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
844844
ffi::cxx_qt_ffi_SecondObject_upcastPtr(this)
845845
}
@@ -867,7 +867,7 @@ impl ::cxx_qt::CxxQtType for ffi::SecondObject {
867867
ffi::cxx_qt_ffi_SecondObject_unsafeRustMut(self)
868868
}
869869
}
870-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::MyRustName {
870+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::MyRustName {
871871
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
872872
ffi::cxx_qt_ffi_MyCxxName_upcastPtr(this)
873873
}
@@ -895,15 +895,15 @@ impl ::cxx_qt::CxxQtType for ffi::MyRustName {
895895
ffi::cxx_qt_ffi_MyCxxName_unsafeRustMut(self)
896896
}
897897
}
898-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::QPushButton {
898+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::QPushButton {
899899
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
900900
ffi::cxx_qt_ffi_QPushButton_upcastPtr(this)
901901
}
902902
unsafe fn from_base_ptr(base: *const ::cxx_qt::QObject) -> *const Self {
903903
ffi::cxx_qt_ffi_QPushButton_downcastPtr(base)
904904
}
905905
}
906-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::ExternObject {
906+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::ExternObject {
907907
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
908908
ffi::cxx_qt_ffi_ExternObjectCpp_upcastPtr(this)
909909
}

crates/cxx-qt-gen/test_outputs/properties.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ cxx_qt::static_assertions::assert_eq_size!(
11101110
cxx_qt::signalhandler::CxxQtSignalHandler<MyObjectCxxQtSignalClosuremy_on_changed>,
11111111
[usize; 2]
11121112
);
1113-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::MyObject {
1113+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::MyObject {
11141114
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
11151115
ffi::cxx_qt_ffi_MyObject_upcastPtr(this)
11161116
}

crates/cxx-qt-gen/test_outputs/qenum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ mod ffi {
169169
type QObject = cxx_qt::QObject;
170170
}
171171
}
172-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::MyObject {
172+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::MyObject {
173173
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
174174
ffi::cxx_qt_ffi_MyObject_upcastPtr(this)
175175
}
@@ -197,7 +197,7 @@ impl ::cxx_qt::CxxQtType for ffi::MyObject {
197197
ffi::cxx_qt_ffi_MyObject_unsafeRustMut(self)
198198
}
199199
}
200-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::MyRenamedObject {
200+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::MyRenamedObject {
201201
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
202202
ffi::cxx_qt_ffi_CxxName_upcastPtr(this)
203203
}

crates/cxx-qt-gen/test_outputs/signals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ cxx_qt::static_assertions::assert_eq_size!(
464464
cxx_qt::signalhandler::CxxQtSignalHandler<MyObjectCxxQtSignalClosurenewData>,
465465
[usize; 2]
466466
);
467-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::MyObject {
467+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::MyObject {
468468
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
469469
ffi::cxx_qt_ffi_MyObject_upcastPtr(this)
470470
}
@@ -492,7 +492,7 @@ impl ::cxx_qt::CxxQtType for ffi::MyObject {
492492
ffi::cxx_qt_ffi_MyObject_unsafeRustMut(self)
493493
}
494494
}
495-
unsafe impl ::cxx_qt::Upcast<::cxx_qt::QObject> for ffi::QTimer {
495+
unsafe impl ::cxx_qt::casting::Upcast<::cxx_qt::QObject> for ffi::QTimer {
496496
unsafe fn upcast_ptr(this: *const Self) -> *const ::cxx_qt::QObject {
497497
ffi::cxx_qt_ffi_QTimer_upcastPtr(this)
498498
}

crates/cxx-qt-lib/src/core/qstringlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::{QList, QString};
66
use core::mem::MaybeUninit;
77
use cxx::{type_id, ExternType};
8-
use cxx_qt::Upcast;
8+
use cxx_qt::casting::Upcast;
99
use std::fmt;
1010
use std::ops::{Deref, DerefMut};
1111

0 commit comments

Comments
 (0)