From d780b92f21dd0e5c7e014590914043108f30f9d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 11 Dec 2018 12:37:15 +0200 Subject: [PATCH] Use an extension trait instead of a custom type for the GStreamer param specs This way they can simply be created via glib::ParamSpec::fraction() for example. --- gstreamer/src/lib.rs | 1 + gstreamer/src/param_spec.rs | 50 +++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 4b40ea27e..9ef3c9347 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -334,6 +334,7 @@ pub mod prelude { pub use gobject::GObjectExtManualGst; pub use object::GstObjectExtManual; pub use pad::PadExtManual; + pub use param_spec::GstParamSpecExt; pub use tag_setter::TagSetterExtManual; pub use value::GstValueExt; diff --git a/gstreamer/src/param_spec.rs b/gstreamer/src/param_spec.rs index 4c3496950..283d2bf0e 100644 --- a/gstreamer/src/param_spec.rs +++ b/gstreamer/src/param_spec.rs @@ -10,11 +10,30 @@ use ffi; use glib; use glib::translate::*; -pub struct ParamSpec(()); - -impl ParamSpec { +pub trait GstParamSpecExt { #[cfg(any(feature = "v1_14", feature = "dox"))] - pub fn array( + fn array( + name: &str, + nick: &str, + blurb: &str, + element_spec: &glib::ParamSpec, + flags: glib::ParamFlags, + ) -> Self; + + fn fraction( + name: &str, + nick: &str, + blurb: &str, + min: ::Fraction, + max: ::Fraction, + default: ::Fraction, + flags: glib::ParamFlags, + ) -> Self; +} + +impl GstParamSpecExt for glib::ParamSpec { + #[cfg(any(feature = "v1_14", feature = "dox"))] + fn array( name: &str, nick: &str, blurb: &str, @@ -32,7 +51,7 @@ impl ParamSpec { } } - pub fn fraction( + fn fraction( name: &str, nick: &str, blurb: &str, @@ -57,3 +76,24 @@ impl ParamSpec { } } } + +#[cfg(test)] +mod tests { + use glib; + use prelude::*; + + #[test] + fn test_trait() { + ::init().unwrap(); + + let _pspec = glib::ParamSpec::fraction( + "foo", + "Foo", + "Foo Bar", + (0, 1).into(), + (100, 1).into(), + (1, 1).into(), + glib::ParamFlags::READWRITE, + ); + } +}