Add the has_name() fn to EventRef, MessageRef and StructureRef

They are handy and they match the C api
This commit is contained in:
Paolo Borelli 2021-12-13 21:00:01 +01:00 committed by Paolo Borelli
parent 9bf5f641ff
commit 97f59d34fa
3 changed files with 15 additions and 0 deletions

View file

@ -216,6 +216,11 @@ impl EventRef {
unsafe { from_glib((*self.as_ptr()).type_) } unsafe { from_glib((*self.as_ptr()).type_) }
} }
#[doc(alias = "gst_event_has_name")]
pub fn has_name(&self, name: &str) -> bool {
self.structure().map_or(false, |s| s.has_name(name))
}
pub fn view(&self) -> EventView<&EventRef> { pub fn view(&self) -> EventView<&EventRef> {
let type_ = unsafe { (*self.as_ptr()).type_ }; let type_ = unsafe { (*self.as_ptr()).type_ };

View file

@ -68,6 +68,11 @@ impl MessageRef {
} }
} }
#[doc(alias = "gst_message_has_name")]
pub fn has_name(&self, name: &str) -> bool {
self.structure().map_or(false, |s| s.has_name(name))
}
pub fn view(&self) -> MessageView { pub fn view(&self) -> MessageView {
let type_ = unsafe { (*self.as_ptr()).type_ }; let type_ = unsafe { (*self.as_ptr()).type_ };

View file

@ -495,6 +495,11 @@ impl StructureRef {
unsafe { ffi::gst_structure_set_name(&mut self.0, name.to_glib_none().0) } unsafe { ffi::gst_structure_set_name(&mut self.0, name.to_glib_none().0) }
} }
#[doc(alias = "gst_structure_has_name")]
pub fn has_name(&self, name: &str) -> bool {
self.name() == name
}
#[doc(alias = "gst_structure_has_field")] #[doc(alias = "gst_structure_has_field")]
pub fn has_field(&self, field: &str) -> bool { pub fn has_field(&self, field: &str) -> bool {
unsafe { unsafe {