Skip to content

Commit f00edfb

Browse files
committed
cxx-qt: automatically implement Upcast<Self> for all types
1 parent 64d4ee6 commit f00edfb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

crates/cxx-qt/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,28 @@ pub trait Upcast<T> {
178178
}
179179
}
180180

181+
impl<T> Upcast<T> for T {
182+
unsafe fn upcast_ptr(this: *const Self) -> *const Self {
183+
this
184+
}
185+
186+
unsafe fn from_base_ptr(base: *const T) -> *const Self {
187+
base
188+
}
189+
190+
fn upcast(&self) -> &Self {
191+
self
192+
}
193+
194+
fn upcast_mut(&mut self) -> &mut Self {
195+
self
196+
}
197+
198+
fn upcast_pin(self: Pin<&mut Self>) -> Pin<&mut Self> {
199+
self
200+
}
201+
}
202+
181203
/// This trait is automatically implemented by CXX-Qt and you most likely do not need to manually implement it.
182204
/// Trait for downcasting to a subclass, provided the subclass implements [Upcast] to this type.
183205
/// Returns `None` in cases where `Sub` isn't a child class of `Self`.

0 commit comments

Comments
 (0)