mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-09-01 01:13:48 +00:00
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:
parent
032e9a7f75
commit
4dabd3bca4
1 changed files with 18 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue