mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-09-03 18:33:51 +00:00
Merge branch 'mini-object-downcast-ref-non-ref' into 'main'
miniobject: Add `downcast_ref()` / `downcast_mut()` variants on the non-ref type too See merge request gstreamer/gstreamer-rs!1780
This commit is contained in:
commit
b189c0a28b
1 changed files with 18 additions and 0 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue