From a954c03bc0a465905e15eba66c2be54b8e1736b4 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 11 Jun 2020 10:53:35 +0200 Subject: [PATCH] functions: rename constructors in manual API The idiomatic way for Rust constructors is to be named from_XXX() instead of new_from_XXX() and with_XXX() instead of new_with_XXX(). Fix #460 --- examples/src/bin/glupload.rs | 19 +++++++++---------- gstreamer-check/src/harness.rs | 6 +++--- gstreamer-gl/src/gl_display_egl.rs | 2 +- gstreamer-gl/src/gl_display_wayland.rs | 2 +- gstreamer-gl/src/gl_display_x11.rs | 4 +--- .../player_video_overlay_video_renderer.rs | 4 ++-- gstreamer-video/src/video_time_code.rs | 6 +++--- gstreamer/src/caps.rs | 8 ++++---- gstreamer/src/ghost_pad.rs | 2 +- gstreamer/src/pad.rs | 2 +- gstreamer/src/pad_template.rs | 2 +- gstreamer/src/promise.rs | 6 +++--- gstreamer/src/value.rs | 16 ++++++++-------- gstreamer/src/value_serde.rs | 4 ++-- 14 files changed, 40 insertions(+), 43 deletions(-) diff --git a/examples/src/bin/glupload.rs b/examples/src/bin/glupload.rs index 261b54812..3cebcbdf7 100644 --- a/examples/src/bin/glupload.rs +++ b/examples/src/bin/glupload.rs @@ -360,18 +360,17 @@ impl App { #[cfg(any(feature = "gl-egl", feature = "gl-wayland"))] RawHandle::Egl(egl_context) => { #[cfg(feature = "gl-egl")] - let gl_display = - if let Some(display) = unsafe { windowed_context.get_egl_display() } { - unsafe { gst_gl::GLDisplayEGL::new_with_egl_display(display as usize) } - .unwrap() - } else { - panic!("EGL context without EGL display"); - }; + let gl_display = if let Some(display) = + unsafe { windowed_context.get_egl_display() } + { + unsafe { gst_gl::GLDisplayEGL::with_egl_display(display as usize) }.unwrap() + } else { + panic!("EGL context without EGL display"); + }; #[cfg(not(feature = "gl-egl"))] let gl_display = if let Some(display) = inner_window.get_wayland_display() { - unsafe { gst_gl::GLDisplayWayland::new_with_display(display as usize) } - .unwrap() + unsafe { gst_gl::GLDisplayWayland::with_display(display as usize) }.unwrap() } else { panic!("Wayland window without Wayland display"); }; @@ -385,7 +384,7 @@ impl App { #[cfg(feature = "gl-x11")] RawHandle::Glx(glx_context) => { let gl_display = if let Some(display) = inner_window.get_xlib_display() { - unsafe { gst_gl::GLDisplayX11::new_with_display(display as usize) }.unwrap() + unsafe { gst_gl::GLDisplayX11::with_display(display as usize) }.unwrap() } else { panic!("X11 window without X Display"); }; diff --git a/gstreamer-check/src/harness.rs b/gstreamer-check/src/harness.rs index fe1cc70a4..7f5c8bbf3 100644 --- a/gstreamer-check/src/harness.rs +++ b/gstreamer-check/src/harness.rs @@ -614,7 +614,7 @@ impl Harness { } } - pub fn new_with_element>( + pub fn with_element>( element: &P, element_sinkpad_name: Option<&str>, element_srcpad_name: Option<&str>, @@ -631,7 +631,7 @@ impl Harness { } } - pub fn new_with_padnames( + pub fn with_padnames( element_name: &str, element_sinkpad_name: Option<&str>, element_srcpad_name: Option<&str>, @@ -648,7 +648,7 @@ impl Harness { } } - pub fn new_with_templates( + pub fn with_templates( element_name: &str, hsrc: Option<&gst::StaticPadTemplate>, hsink: Option<&gst::StaticPadTemplate>, diff --git a/gstreamer-gl/src/gl_display_egl.rs b/gstreamer-gl/src/gl_display_egl.rs index 565169509..22dc12909 100644 --- a/gstreamer-gl/src/gl_display_egl.rs +++ b/gstreamer-gl/src/gl_display_egl.rs @@ -14,7 +14,7 @@ use GLDisplayEGL; use GLDisplayType; impl GLDisplayEGL { - pub unsafe fn new_with_egl_display( + pub unsafe fn with_egl_display( display: uintptr_t, ) -> Result { let result = from_glib_full(gst_gl_sys::gst_gl_display_egl_new_with_egl_display( diff --git a/gstreamer-gl/src/gl_display_wayland.rs b/gstreamer-gl/src/gl_display_wayland.rs index 0d06fd386..24bf690d8 100644 --- a/gstreamer-gl/src/gl_display_wayland.rs +++ b/gstreamer-gl/src/gl_display_wayland.rs @@ -13,7 +13,7 @@ use libc::uintptr_t; use GLDisplayWayland; impl GLDisplayWayland { - pub unsafe fn new_with_display( + pub unsafe fn with_display( display: uintptr_t, ) -> Result { let result = from_glib_full(gst_gl_sys::gst_gl_display_wayland_new_with_display( diff --git a/gstreamer-gl/src/gl_display_x11.rs b/gstreamer-gl/src/gl_display_x11.rs index 554a50cdd..6a1d23750 100644 --- a/gstreamer-gl/src/gl_display_x11.rs +++ b/gstreamer-gl/src/gl_display_x11.rs @@ -13,9 +13,7 @@ use libc::uintptr_t; use GLDisplayX11; impl GLDisplayX11 { - pub unsafe fn new_with_display( - display: uintptr_t, - ) -> Result { + pub unsafe fn with_display(display: uintptr_t) -> Result { let result = from_glib_full(gst_gl_sys::gst_gl_display_x11_new_with_display( display as gpointer, )); diff --git a/gstreamer-player/src/player_video_overlay_video_renderer.rs b/gstreamer-player/src/player_video_overlay_video_renderer.rs index 1c035ba3c..da06dd41d 100644 --- a/gstreamer-player/src/player_video_overlay_video_renderer.rs +++ b/gstreamer-player/src/player_video_overlay_video_renderer.rs @@ -25,7 +25,7 @@ impl PlayerVideoOverlayVideoRenderer { ) as *mut _) } - pub unsafe fn new_with_handle_and_sink>( + pub unsafe fn with_handle_and_sink>( window_handle: uintptr_t, video_sink: &P, ) -> PlayerVideoOverlayVideoRenderer { @@ -39,7 +39,7 @@ impl PlayerVideoOverlayVideoRenderer { ) } - pub fn new_with_sink>(video_sink: &P) -> PlayerVideoOverlayVideoRenderer { + pub fn with_sink>(video_sink: &P) -> PlayerVideoOverlayVideoRenderer { assert_initialized_main_thread!(); unsafe { diff --git a/gstreamer-video/src/video_time_code.rs b/gstreamer-video/src/video_time_code.rs index c2530483f..c037982cd 100644 --- a/gstreamer-video/src/video_time_code.rs +++ b/gstreamer-video/src/video_time_code.rs @@ -72,7 +72,7 @@ impl VideoTimeCode { } #[cfg(any(feature = "v1_16", feature = "dox"))] - pub fn new_from_date_time( + pub fn from_date_time( fps: gst::Fraction, dt: &glib::DateTime, flags: VideoTimeCodeFlags, @@ -183,13 +183,13 @@ impl ValidVideoTimeCode { } // #[cfg(any(feature = "v1_16", feature = "dox"))] - // pub fn new_from_date_time( + // pub fn from_date_time( // fps: gst::Fraction, // dt: &glib::DateTime, // flags: VideoTimeCodeFlags, // field_count: u32, // ) -> Option { - // let tc = VideoTimeCode::new_from_date_time(fps, dt, flags, field_count); + // let tc = VideoTimeCode::from_date_time(fps, dt, flags, field_count); // tc.and_then(|tc| tc.try_into().ok()) // } diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs index 090e4d428..61ce5b3ef 100644 --- a/gstreamer/src/caps.rs +++ b/gstreamer/src/caps.rs @@ -42,12 +42,12 @@ impl Caps { pub fn builder_full_with_features(features: CapsFeatures) -> BuilderFull { assert_initialized_main_thread!(); - BuilderFull::new_with_features(features) + BuilderFull::with_features(features) } pub fn builder_full_with_any_features() -> BuilderFull { assert_initialized_main_thread!(); - BuilderFull::new_with_any_features() + BuilderFull::with_any_features() } pub fn new_empty() -> Self { @@ -669,7 +669,7 @@ impl BuilderFull { } } - fn new_with_features(features: CapsFeatures) -> Self { + fn with_features(features: CapsFeatures) -> Self { skip_assert_initialized!(); BuilderFull { caps: Caps::new_empty(), @@ -688,7 +688,7 @@ impl BuilderFull { } impl BuilderFull { - fn new_with_any_features() -> Self { + fn with_any_features() -> Self { BuilderFull { caps: Caps::new_empty(), features: Some(CapsFeatures::new_any()), diff --git a/gstreamer/src/ghost_pad.rs b/gstreamer/src/ghost_pad.rs index aeda62e95..8f5d809b6 100644 --- a/gstreamer/src/ghost_pad.rs +++ b/gstreamer/src/ghost_pad.rs @@ -30,7 +30,7 @@ impl GhostPad { } } - pub fn new_from_template>( + pub fn from_template>( name: Option<&str>, target: &Q, templ: &PadTemplate, diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index e5d868763..9adb420f4 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -50,7 +50,7 @@ use libc; use gst_sys; impl Pad { - pub fn new_from_static_template(templ: &StaticPadTemplate, name: Option<&str>) -> Pad { + pub fn from_static_template(templ: &StaticPadTemplate, name: Option<&str>) -> Pad { assert_initialized_main_thread!(); unsafe { from_glib_none(gst_sys::gst_pad_new_from_static_template( diff --git a/gstreamer/src/pad_template.rs b/gstreamer/src/pad_template.rs index e56ed022e..795024c64 100644 --- a/gstreamer/src/pad_template.rs +++ b/gstreamer/src/pad_template.rs @@ -19,7 +19,7 @@ use gst_sys; impl PadTemplate { #[cfg(any(feature = "v1_14", feature = "dox"))] - pub fn new_from_static_pad_template_with_gtype( + pub fn from_static_pad_template_with_gtype( pad_template: &StaticPadTemplate, pad_type: glib::types::Type, ) -> Result { diff --git a/gstreamer/src/promise.rs b/gstreamer/src/promise.rs index 96cb3dce8..e4182ff12 100644 --- a/gstreamer/src/promise.rs +++ b/gstreamer/src/promise.rs @@ -42,7 +42,7 @@ impl Promise { unsafe { from_glib_full(gst_sys::gst_promise_new()) } } - pub fn new_with_change_func(func: F) -> Promise + pub fn with_change_func(func: F) -> Promise where F: FnOnce(Result, PromiseError>) + Send + 'static, { @@ -95,7 +95,7 @@ impl Promise { // We only use the channel as a convenient waker let (sender, receiver) = oneshot::channel(); - let promise = Self::new_with_change_func(move |_res| { + let promise = Self::with_change_func(move |_res| { let _ = sender.send(()); }); @@ -199,7 +199,7 @@ mod tests { ::init().unwrap(); let (sender, receiver) = channel(); - let promise = Promise::new_with_change_func(move |res| { + let promise = Promise::with_change_func(move |res| { sender.send(res.map(|s| s.map(ToOwned::to_owned))).unwrap(); }); diff --git a/gstreamer/src/value.rs b/gstreamer/src/value.rs index d9e436b68..7e1ebe0e3 100644 --- a/gstreamer/src/value.rs +++ b/gstreamer/src/value.rs @@ -298,10 +298,10 @@ impl IntRange { impl IntRange { pub fn new(min: i32, max: i32) -> Self { skip_assert_initialized!(); - Self::new_with_step(min, max, 1) + Self::with_step(min, max, 1) } - pub fn new_with_step(min: i32, max: i32, step: i32) -> Self { + pub fn with_step(min: i32, max: i32, step: i32) -> Self { assert_initialized_main_thread!(); assert!(min <= max); @@ -314,10 +314,10 @@ impl IntRange { impl IntRange { pub fn new(min: i64, max: i64) -> Self { skip_assert_initialized!(); - Self::new_with_step(min, max, 1) + Self::with_step(min, max, 1) } - pub fn new_with_step(min: i64, max: i64, step: i64) -> Self { + pub fn with_step(min: i64, max: i64, step: i64) -> Self { assert_initialized_main_thread!(); assert!(min <= max); @@ -337,7 +337,7 @@ impl From<(i32, i32)> for IntRange { impl From<(i32, i32, i32)> for IntRange { fn from((min, max, step): (i32, i32, i32)) -> Self { skip_assert_initialized!(); - Self::new_with_step(min, max, step) + Self::with_step(min, max, step) } } @@ -351,7 +351,7 @@ impl From<(i64, i64)> for IntRange { impl From<(i64, i64, i64)> for IntRange { fn from((min, max, step): (i64, i64, i64)) -> Self { skip_assert_initialized!(); - Self::new_with_step(min, max, step) + Self::with_step(min, max, step) } } @@ -367,7 +367,7 @@ impl<'a> FromValue<'a> for IntRange { let max = gst_sys::gst_value_get_int_range_max(v.to_glib_none().0); let step = gst_sys::gst_value_get_int_range_step(v.to_glib_none().0); - Self::new_with_step(min, max, step) + Self::with_step(min, max, step) } } @@ -395,7 +395,7 @@ impl<'a> FromValue<'a> for IntRange { let max = gst_sys::gst_value_get_int64_range_max(v.to_glib_none().0); let step = gst_sys::gst_value_get_int64_range_step(v.to_glib_none().0); - Self::new_with_step(min, max, step) + Self::with_step(min, max, step) } } diff --git a/gstreamer/src/value_serde.rs b/gstreamer/src/value_serde.rs index dd857ef14..3b06d1c38 100644 --- a/gstreamer/src/value_serde.rs +++ b/gstreamer/src/value_serde.rs @@ -345,7 +345,7 @@ mod tests { assert_eq!(r#"{"min":[1,3],"max":[1,2]}"#.to_owned(), res); // IntRange - let int_range = IntRange::::new_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,); @@ -550,7 +550,7 @@ mod tests { ); // IntRange - let int_range = IntRange::::new_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());