diff --git a/gstreamer-audio/src/functions.rs b/gstreamer-audio/src/functions.rs index dac9bc98a..eafb8cb99 100644 --- a/gstreamer-audio/src/functions.rs +++ b/gstreamer-audio/src/functions.rs @@ -59,8 +59,8 @@ pub fn audio_make_raw_caps( let builder = gst::caps::Caps::builder("audio/x-raw") .field("format", gst::List::from_values(formats)) - .field("rate", gst::IntRange::::new(1, i32::MAX)) - .field("channels", gst::IntRange::::new(1, i32::MAX)); + .field("rate", gst::IntRange::new(1, i32::MAX)) + .field("channels", gst::IntRange::new(1, i32::MAX)); match layout { crate::AudioLayout::Interleaved => builder.field("layout", "interleaved"), diff --git a/gstreamer-video/src/functions.rs b/gstreamer-video/src/functions.rs index 1972cf581..5aef5a977 100644 --- a/gstreamer-video/src/functions.rs +++ b/gstreamer-video/src/functions.rs @@ -209,8 +209,8 @@ pub fn video_make_raw_caps( gst::caps::Caps::builder("video/x-raw") .field("format", gst::List::from_values(formats)) - .field("width", gst::IntRange::::new(1, i32::MAX)) - .field("height", gst::IntRange::::new(1, i32::MAX)) + .field("width", gst::IntRange::new(1, i32::MAX)) + .field("height", gst::IntRange::new(1, i32::MAX)) .field( "framerate", gst::FractionRange::new(gst::Fraction::new(0, 1), gst::Fraction::new(i32::MAX, 1)), diff --git a/gstreamer/src/value.rs b/gstreamer/src/value.rs index 9d6c515f4..05bb24526 100644 --- a/gstreamer/src/value.rs +++ b/gstreamer/src/value.rs @@ -295,35 +295,53 @@ impl IntRange { } } -impl IntRange { - pub fn new(min: i32, max: i32) -> Self { +#[doc(hidden)] +pub trait IntRangeType: Sized + Clone + Copy + 'static { + fn with_min_max(min: Self, max: Self) -> IntRange; + fn with_step(min: Self, max: Self, step: Self) -> IntRange; +} + +impl IntRangeType for i32 { + fn with_min_max(min: i32, max: i32) -> IntRange { skip_assert_initialized!(); - Self::with_step(min, max, 1) + IntRange { min, max, step: 1 } } - pub fn with_step(min: i32, max: i32, step: i32) -> Self { + fn with_step(min: i32, max: i32, step: i32) -> IntRange { assert_initialized_main_thread!(); assert!(min <= max); assert!(step > 0); - Self { min, max, step } + IntRange { min, max, step } } } -impl IntRange { - pub fn new(min: i64, max: i64) -> Self { +impl IntRangeType for i64 { + fn with_min_max(min: i64, max: i64) -> IntRange { skip_assert_initialized!(); - Self::with_step(min, max, 1) + IntRange { min, max, step: 1 } } - pub fn with_step(min: i64, max: i64, step: i64) -> Self { + fn with_step(min: i64, max: i64, step: i64) -> IntRange { assert_initialized_main_thread!(); assert!(min <= max); assert!(step > 0); - Self { min, max, step } + IntRange { min, max, step } + } +} + +impl IntRange { + pub fn new(min: T, max: T) -> IntRange { + assert_initialized_main_thread!(); + T::with_min_max(min, max) + } + + pub fn with_step(min: T, max: T, step: T) -> IntRange { + assert_initialized_main_thread!(); + T::with_step(min, max, step) } } @@ -1193,6 +1211,15 @@ mod tests { assert_eq!(f3, crate::Fraction::new(2, 27)); } + #[test] + fn test_int_range_constructor() { + crate::init().unwrap(); + + // Type inference should figure out the type + let _r1 = crate::IntRange::new(1i32, 2i32); + let _r2 = crate::IntRange::with_step(2i64, 3i64, 4i64); + } + #[test] fn test_deserialize() { crate::init().unwrap(); diff --git a/gstreamer/src/value_serde.rs b/gstreamer/src/value_serde.rs index 170782b03..7c6090155 100644 --- a/gstreamer/src/value_serde.rs +++ b/gstreamer/src/value_serde.rs @@ -322,7 +322,7 @@ mod tests { assert_eq!(r#"{"min":[1,3],"max":[1,2]}"#.to_owned(), res); // IntRange - let int_range = IntRange::::with_step(0, 42, 21); + let int_range = IntRange::with_step(0, 42, 21); let res = ron::ser::to_string_pretty(&int_range, pretty_config.clone()); assert_eq!(Ok("( min: 0, max: 42, step: 21,)".to_owned()), res,); @@ -455,7 +455,7 @@ mod tests { ); // IntRange - let int_range = IntRange::::with_step(0, 42, 21); + let int_range = IntRange::with_step(0, 42, 21); let int_range_ser = ron::ser::to_string(&int_range).unwrap(); let int_range_de: IntRange = ron::de::from_str(int_range_ser.as_str()).unwrap(); assert_eq!(int_range_de.min(), int_range.min());