diff --git a/gstreamer-audio/src/audio_format.rs b/gstreamer-audio/src/audio_format.rs index 30642c5a8..0030e8730 100644 --- a/gstreamer-audio/src/audio_format.rs +++ b/gstreamer-audio/src/audio_format.rs @@ -118,14 +118,17 @@ impl crate::AudioFormat { } pub fn to_str<'a>(self) -> &'a str { - if self == crate::AudioFormat::Unknown { + if self == Self::Unknown { return "UNKNOWN"; } - unsafe { - CStr::from_ptr(ffi::gst_audio_format_to_string(self.to_glib())) - .to_str() - .unwrap() + CStr::from_ptr( + ffi::gst_audio_format_to_string(self.to_glib()) + .as_ref() + .expect("gst_audio_format_to_string returned NULL"), + ) + .to_str() + .expect("gst_audio_format_to_string returned an invalid string") } } diff --git a/gstreamer-video/src/video_format.rs b/gstreamer-video/src/video_format.rs index 82cf399a0..ff506d296 100644 --- a/gstreamer-video/src/video_format.rs +++ b/gstreamer-video/src/video_format.rs @@ -313,14 +313,17 @@ impl crate::VideoFormat { } pub fn to_str<'a>(self) -> &'a str { - if self == crate::VideoFormat::Unknown { + if self == Self::Unknown { return "UNKNOWN"; } - unsafe { - CStr::from_ptr(ffi::gst_video_format_to_string(self.to_glib())) - .to_str() - .unwrap() + CStr::from_ptr( + ffi::gst_video_format_to_string(self.to_glib()) + .as_ref() + .expect("gst_video_format_to_string returned NULL"), + ) + .to_str() + .expect("gst_video_format_to_string returned an invalid string") } } diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index d90257104..02a3e66c1 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -935,10 +935,17 @@ impl glib::translate::FromGlibPtrFull<*mut ffi::GstVideoInfo> for VideoInfo { #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_12")))] impl crate::VideoFieldOrder { pub fn to_str<'a>(self) -> &'a str { + if self == Self::Unknown { + return "UNKNOWN"; + } unsafe { - CStr::from_ptr(ffi::gst_video_field_order_to_string(self.to_glib())) - .to_str() - .unwrap() + CStr::from_ptr( + ffi::gst_video_field_order_to_string(self.to_glib()) + .as_ref() + .expect("gst_video_field_order_to_string returned NULL"), + ) + .to_str() + .expect("gst_video_field_order_to_string returned an invalid string") } } }