From 27d191f8547e8a441bc77704c4b24e3a3aba70e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 27 Jul 2017 23:36:44 +0100 Subject: [PATCH] Use &ToValue instead of &Value for simple structure/caps setters/constructors --- gstreamer/src/caps.rs | 24 +++++++++++++----------- gstreamer/src/structure.rs | 10 +++++----- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs index c3a22ad5f..7ce4ccff1 100644 --- a/gstreamer/src/caps.rs +++ b/gstreamer/src/caps.rs @@ -16,6 +16,7 @@ use CapsIntersectMode; use glib; use ffi; use glib::translate::{from_glib, from_glib_none, from_glib_full, ToGlibPtr, ToGlib}; +use glib::value::ToValue; #[repr(C)] pub struct CapsRef(ffi::GstCaps); @@ -37,7 +38,7 @@ impl GstRc { unsafe { from_glib_full(ffi::gst_caps_new_any()) } } - pub fn new_simple(name: &str, values: &[(&str, &glib::Value)]) -> Self { + pub fn new_simple(name: &str, values: &[(&str, &ToValue)]) -> Self { assert_initialized_main_thread!(); let mut caps = Caps::new_empty(); @@ -103,8 +104,10 @@ impl str::FromStr for Caps { } impl CapsRef { - pub fn set_simple(&mut self, values: &[(&str, &glib::Value)]) { + pub fn set_simple(&mut self, values: &[(&str, &ToValue)]) { for &(name, ref value) in values { + let value = value.to_value(); + unsafe { ffi::gst_caps_set_value( self.as_mut_ptr(), @@ -355,7 +358,6 @@ unsafe impl Send for CapsRef {} #[cfg(test)] mod tests { use super::*; - use glib::ToValue; use Fraction; #[test] @@ -365,10 +367,10 @@ mod tests { let caps = Caps::new_simple( "foo/bar", &[ - ("int", &12.to_value()), - ("bool", &true.to_value()), - ("string", &"bla".to_value()), - ("fraction", &Fraction::new(1, 2).to_value()), + ("int", &12), + ("bool", &true), + ("string", &"bla"), + ("fraction", &Fraction::new(1, 2)), //("array", vec![1.into(), 2.into()].into()), ], ); @@ -385,10 +387,10 @@ mod tests { Structure::new( "foo/bar", &[ - ("int", &12.to_value()), - ("bool", &true.to_value()), - ("string", &"bla".to_value()), - ("fraction", &Fraction::new(1, 2).to_value()) + ("int", &12), + ("bool", &true), + ("string", &"bla"), + ("fraction", &Fraction::new(1, 2)) //("array", vec![1.into(), 2.into()].into()), ], ).as_ref() diff --git a/gstreamer/src/structure.rs b/gstreamer/src/structure.rs index 0cdeb4425..e01c325c5 100644 --- a/gstreamer/src/structure.rs +++ b/gstreamer/src/structure.rs @@ -34,12 +34,12 @@ impl Structure { ) } - pub fn new(name: &str, values: &[(&str, &Value)]) -> Structure { + pub fn new(name: &str, values: &[(&str, &ToValue)]) -> Structure { assert_initialized_main_thread!(); let mut structure = Structure::new_empty(name); for &(f, v) in values { - structure.set_value(f, v.clone()); + structure.set_value(f, v.to_value()); } structure @@ -590,9 +590,9 @@ mod tests { let s2 = Structure::new( "test", &[ - ("f1", &"abc".to_value()), - ("f2", &"bcd".to_value()), - ("f3", &123i32.to_value()), + ("f1", &"abc"), + ("f2", &"bcd"), + ("f3", &123i32), ], ); assert_eq!(s, s2);