@@ -127,19 +127,30 @@ pub trait Threading: Sized {
127
127
fn threading_drop ( cxx_qt_thread : & mut CxxQtThread < Self > ) ;
128
128
}
129
129
130
- /// This trait is automatically implemented by CXX-Qt and should not be manually implemented
131
- /// Allows upcasting to either QObject or the provided base class of a type
132
- /// Will not be implemented if no types inherit from QObject or base.
130
+ /// This trait is automatically implemented by CXX-Qt and you most likely do not need to manually implement it.
131
+ /// Allows upcasting to either [ QObject] or the provided base class of a type.
132
+ /// Will not be implemented if no types inherit from [ QObject] or have the `#[ base = T]` attribute .
133
133
pub trait Upcast < T > {
134
134
#[ doc( hidden) ]
135
- /// Internal function, Should not be implemented manually
135
+ /// # Safety
136
+ ///
137
+ /// Internal function, Should probably not be implemented manually unless you're absolutely sure you need it.
138
+ /// Automatically available for types in RustQt blocks in [cxx_qt::bridge](bridge)s.
139
+ /// Upcasts a pointer to `Self` to a pointer to the base class `T`.
140
+ /// > Note: Internal implementation uses `static_cast`.
136
141
unsafe fn upcast_ptr ( this : * const Self ) -> * const T ;
137
142
138
143
#[ doc( hidden) ]
139
- /// Internal function, Should not be implemented manually
144
+ /// # Safety
145
+ ///
146
+ /// Internal function, Should probably not be implemented manually unless you're absolutely sure you need it.
147
+ /// Automatically available for types in RustQt blocks in [cxx_qt::bridge](bridge)s.
148
+ /// Downcasts a pointer to base class `T` to a pointer to `Self`.
149
+ /// Return a null pointer if `Self` is not actually a child of base.
150
+ /// > Note: Internal implementation uses `dynamic_cast`.
140
151
unsafe fn from_base_ptr ( base : * const T ) -> * const Self ;
141
152
142
- /// Upcast a reference to a reference to the base class
153
+ /// Upcast a reference to self to a reference to the base class
143
154
fn upcast ( & self ) -> & T {
144
155
let ptr = self as * const Self ;
145
156
unsafe {
@@ -148,7 +159,7 @@ pub trait Upcast<T> {
148
159
}
149
160
}
150
161
151
- /// Upcast a mutable reference to a mutable reference to the base class
162
+ /// Upcast a mutable reference to sell to a mutable reference to the base class
152
163
fn upcast_mut ( & mut self ) -> & mut T {
153
164
let ptr = self as * const Self ;
154
165
unsafe {
@@ -157,7 +168,7 @@ pub trait Upcast<T> {
157
168
}
158
169
}
159
170
160
- /// Upcast a pinned mutable reference to a pinned mutable reference to the base class
171
+ /// Upcast a pinned mutable reference to self to a pinned mutable reference to the base class
161
172
fn upcast_pin ( self : Pin < & mut Self > ) -> Pin < & mut T > {
162
173
let this = self . deref ( ) as * const Self ;
163
174
unsafe {
@@ -167,9 +178,11 @@ pub trait Upcast<T> {
167
178
}
168
179
}
169
180
170
- /// Trait for downcasting to a subclass, provided the subclass implements Upcast to this type
181
+ /// This trait is automatically implemented by CXX-Qt and you most likely do not need to manually implement it.
182
+ /// Trait for downcasting to a subclass, provided the subclass implements [Upcast] to this type.
183
+ /// Returns `None` in cases where `Sub` isn't a child class of `Self`.
171
184
pub trait Downcast : Sized {
172
- /// try Downcast to a subclass of this, given that the subclass upcasts to this type
185
+ /// Try to downcast to a subclass of this type , given that the subclass upcasts to this type
173
186
fn downcast < Sub : Upcast < Self > > ( & self ) -> Option < & Sub > {
174
187
unsafe {
175
188
let ptr = Sub :: from_base_ptr ( self as * const Self ) ;
@@ -181,7 +194,7 @@ pub trait Downcast: Sized {
181
194
}
182
195
}
183
196
184
- /// try Downcast mutably to a subclass of this, given that the subclass upcasts to this type
197
+ /// Try to downcast mutably to a subclass of this, given that the subclass upcasts to this type
185
198
fn downcast_mut < Sub : Upcast < Self > > ( & mut self ) -> Option < & mut Sub > {
186
199
unsafe {
187
200
let ptr = Sub :: from_base_ptr ( self as * const Self ) as * mut Sub ;
@@ -193,7 +206,7 @@ pub trait Downcast: Sized {
193
206
}
194
207
}
195
208
196
- /// try Downcast a pin to a pinned subclass of this, given that the subclass upcasts to this type
209
+ /// Try to downcast a pin to a pinned subclass of this, given that the subclass upcasts to this type
197
210
fn downcast_pin < Sub : Upcast < Self > > ( self : Pin < & mut Self > ) -> Option < Pin < & mut Sub > > {
198
211
let this = self . deref ( ) as * const Self ;
199
212
unsafe {
@@ -207,6 +220,7 @@ pub trait Downcast: Sized {
207
220
}
208
221
}
209
222
223
+ /// Automatic implementation of Downcast for any applicable types
210
224
impl < T : Sized > Downcast for T { }
211
225
212
226
/// This trait can be implemented on any [CxxQtType] to define a
0 commit comments