From c5c9fd81e438e79d45a89e9f7db3e0df0f1e9491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 17 Aug 2021 08:47:02 +0300 Subject: [PATCH] gstreamer: Value::deserialize() needs to take the target type as parameter Otherwise it will always fail. --- gstreamer/src/value.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/gstreamer/src/value.rs b/gstreamer/src/value.rs index 761861763..5316998e0 100644 --- a/gstreamer/src/value.rs +++ b/gstreamer/src/value.rs @@ -836,7 +836,10 @@ pub trait GstValueExt: Sized { #[doc(alias = "gst_value_serialize")] fn serialize(&self) -> Result; #[doc(alias = "gst_value_deserialize")] - fn deserialize<'a, T: Into<&'a str>>(s: T) -> Result; + fn deserialize<'a, T: Into<&'a str>>( + s: T, + type_: glib::Type, + ) -> Result; } impl GstValueExt for glib::Value { @@ -976,13 +979,16 @@ impl GstValueExt for glib::Value { } } - fn deserialize<'a, T: Into<&'a str>>(s: T) -> Result { + fn deserialize<'a, T: Into<&'a str>>( + s: T, + type_: glib::Type, + ) -> Result { assert_initialized_main_thread!(); let s = s.into(); unsafe { - let mut value = glib::Value::uninitialized(); + let mut value = glib::Value::from_type(type_); let ret: bool = from_glib(ffi::gst_value_deserialize( value.to_glib_none_mut().0, s.to_glib_none().0, @@ -998,6 +1004,8 @@ impl GstValueExt for glib::Value { #[cfg(test)] mod tests { + use super::*; + #[test] fn test_fraction() { crate::init().unwrap(); @@ -1011,4 +1019,12 @@ mod tests { assert_eq!(f3, crate::Fraction::new(2, 27)); } + + #[test] + fn test_deserialize() { + crate::init().unwrap(); + + let v = glib::Value::deserialize("123", i32::static_type()).unwrap(); + assert_eq!(v.get::(), Ok(123)); + } }