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

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1780>
This commit is contained in:
Sebastian Dröge 2025-08-27 12:39:46 +03:00 committed by GStreamer Marge Bot
parent 032e9a7f75
commit 4dabd3bca4

View file

@ -647,6 +647,24 @@ impl MiniObject {
Err(self) 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 { impl fmt::Debug for MiniObject {