Merge branch 'mini-object-downcast-ref-non-ref' into 'main'

miniobject: Add `downcast_ref()` / `downcast_mut()` variants on the non-ref type too

See merge request gstreamer/gstreamer-rs!1780
This commit is contained in:
Sebastian Dröge 2025-08-28 10:13:53 +03:00
commit b189c0a28b

View file

@ -647,6 +647,24 @@ impl MiniObject {
Err(self)
}
}
#[inline]
pub fn downcast_ref<T: IsMiniObject + StaticType>(&self) -> Option<&T> {
if self.type_().is_a(T::static_type()) {
unsafe { Some(&*(self as *const Self as *const T)) }
} else {
None
}
}
#[inline]
pub fn downcast_mut<T: IsMiniObject + StaticType>(&mut self) -> Option<&mut T> {
if self.type_().is_a(T::static_type()) {
unsafe { Some(&mut *(self as *mut Self as *mut T)) }
} else {
None
}
}
}
impl fmt::Debug for MiniObject {