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 {