File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 9
9
//!
10
10
//! See the [book](https://kdab.github.io/cxx-qt/book/) for more information.
11
11
12
- use std:: { fs:: File , io:: Write , path:: Path } ;
12
+ use std:: { fs:: File , io:: Write , path:: Path , pin :: Pin } ;
13
13
14
14
#[ doc( hidden) ]
15
15
pub mod casting;
@@ -125,6 +125,26 @@ pub use threading::{CxxQtThread, ThreadingQueueError};
125
125
#[ doc( hidden) ]
126
126
pub use static_assertions;
127
127
128
+ /// This trait provides wrappers for objects which are QObjects or can be turned into a [QObject].
129
+ /// It is automatically implemented for any types which implement [casting::Upcast] to a [QObject].
130
+ pub trait AsObject {
131
+ /// Cast self reference into a [QObject] reference
132
+ fn as_qobject ( & self ) -> & QObject ;
133
+
134
+ /// Cast pinned mutable reference into a pinned mutable [QObject] reference
135
+ fn as_qobject_mut ( self : Pin < & mut Self > ) -> Pin < & mut QObject > ;
136
+ }
137
+
138
+ impl < T : casting:: Upcast < QObject > > AsObject for T {
139
+ fn as_qobject ( & self ) -> & QObject {
140
+ self . upcast ( )
141
+ }
142
+
143
+ fn as_qobject_mut ( self : Pin < & mut Self > ) -> Pin < & mut QObject > {
144
+ self . upcast_pin ( )
145
+ }
146
+ }
147
+
128
148
/// This trait is automatically implemented for all QObject types generated by CXX-Qt.
129
149
/// It provides information about the inner Rust struct that is wrapped by the QObject, as well as the methods
130
150
/// that Cxx-Qt will generate for the QObject.
You can’t perform that action at this time.
0 commit comments