From 4dabd3bca408dc799d2f68fcf551a01bd2f55769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 27 Aug 2025 12:39:46 +0300 Subject: [PATCH] miniobject: Add `downcast_ref()` / `downcast_mut()` variants on the non-ref type too Part-of: --- gstreamer/src/miniobject.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gstreamer/src/miniobject.rs b/gstreamer/src/miniobject.rs index 49dbad19d..1cb3a5477 100644 --- a/gstreamer/src/miniobject.rs +++ b/gstreamer/src/miniobject.rs @@ -647,6 +647,24 @@ impl MiniObject { Err(self) } } + + #[inline] + pub fn downcast_ref(&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(&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 {