From a26fcaf0adea72581e08bec5a6114b19d102cf00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 26 Oct 2023 13:39:44 +0300 Subject: [PATCH] gstreamer: meta: Add `upcast_ref()` function to go from a specific to a generic meta Part-of: --- gstreamer/src/meta.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gstreamer/src/meta.rs b/gstreamer/src/meta.rs index 14e3eec64..ebf774bea 100644 --- a/gstreamer/src/meta.rs +++ b/gstreamer/src/meta.rs @@ -212,6 +212,11 @@ impl<'a, T> MetaRef<'a, T> { } } + #[inline] + pub fn upcast_ref(&self) -> &MetaRef<'a, Meta> { + unsafe { &*(self as *const MetaRef<'a, T> as *const MetaRef<'a, Meta>) } + } + #[inline] pub fn as_ptr(&self) -> *const T::GstType where @@ -288,6 +293,16 @@ impl<'a, T, U> MetaRefMut<'a, T, U> { } } + #[inline] + pub fn upcast_ref(&self) -> &MetaRef<'a, Meta> { + unsafe { &*(self as *const MetaRefMut<'a, T, U> as *const MetaRef<'a, Meta>) } + } + + #[inline] + pub fn upcast_mut(&mut self) -> &MetaRefMut<'a, Meta, U> { + unsafe { &mut *(self as *mut MetaRefMut<'a, T, U> as *mut MetaRefMut<'a, Meta, U>) } + } + #[inline] pub fn as_ptr(&self) -> *const T::GstType where