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.
This commit is contained in:
Sebastian Dröge 2018-12-11 12:37:15 +02:00
parent 43f5a10f9c
commit d780b92f21
2 changed files with 46 additions and 5 deletions

View file

@ -334,6 +334,7 @@ pub mod prelude {
pub use gobject::GObjectExtManualGst; pub use gobject::GObjectExtManualGst;
pub use object::GstObjectExtManual; pub use object::GstObjectExtManual;
pub use pad::PadExtManual; pub use pad::PadExtManual;
pub use param_spec::GstParamSpecExt;
pub use tag_setter::TagSetterExtManual; pub use tag_setter::TagSetterExtManual;
pub use value::GstValueExt; pub use value::GstValueExt;

View file

@ -10,11 +10,30 @@ use ffi;
use glib; use glib;
use glib::translate::*; use glib::translate::*;
pub struct ParamSpec(()); pub trait GstParamSpecExt {
impl ParamSpec {
#[cfg(any(feature = "v1_14", feature = "dox"))] #[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, name: &str,
nick: &str, nick: &str,
blurb: &str, blurb: &str,
@ -32,7 +51,7 @@ impl ParamSpec {
} }
} }
pub fn fraction( fn fraction(
name: &str, name: &str,
nick: &str, nick: &str,
blurb: &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,
);
}
}