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
This commit is contained in:
Guillaume Desmottes 2020-06-11 10:53:35 +02:00
parent 7b2fe31cc1
commit a954c03bc0
14 changed files with 40 additions and 43 deletions

View file

@ -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");
};

View file

@ -614,7 +614,7 @@ impl Harness {
}
}
pub fn new_with_element<P: IsA<gst::Element>>(
pub fn with_element<P: IsA<gst::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>,

View file

@ -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<GLDisplayEGL, glib::error::BoolError> {
let result = from_glib_full(gst_gl_sys::gst_gl_display_egl_new_with_egl_display(

View file

@ -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<GLDisplayWayland, glib::error::BoolError> {
let result = from_glib_full(gst_gl_sys::gst_gl_display_wayland_new_with_display(

View file

@ -13,9 +13,7 @@ use libc::uintptr_t;
use GLDisplayX11;
impl GLDisplayX11 {
pub unsafe fn new_with_display(
display: uintptr_t,
) -> Result<GLDisplayX11, glib::error::BoolError> {
pub unsafe fn with_display(display: uintptr_t) -> Result<GLDisplayX11, glib::error::BoolError> {
let result = from_glib_full(gst_gl_sys::gst_gl_display_x11_new_with_display(
display as gpointer,
));

View file

@ -25,7 +25,7 @@ impl PlayerVideoOverlayVideoRenderer {
) as *mut _)
}
pub unsafe fn new_with_handle_and_sink<P: IsA<gst::Element>>(
pub unsafe fn with_handle_and_sink<P: IsA<gst::Element>>(
window_handle: uintptr_t,
video_sink: &P,
) -> PlayerVideoOverlayVideoRenderer {
@ -39,7 +39,7 @@ impl PlayerVideoOverlayVideoRenderer {
)
}
pub fn new_with_sink<P: IsA<gst::Element>>(video_sink: &P) -> PlayerVideoOverlayVideoRenderer {
pub fn with_sink<P: IsA<gst::Element>>(video_sink: &P) -> PlayerVideoOverlayVideoRenderer {
assert_initialized_main_thread!();
unsafe {

View file

@ -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<VideoTimeCode> {
// 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())
// }

View file

@ -42,12 +42,12 @@ impl Caps {
pub fn builder_full_with_features(features: CapsFeatures) -> BuilderFull<SomeFeatures> {
assert_initialized_main_thread!();
BuilderFull::new_with_features(features)
BuilderFull::with_features(features)
}
pub fn builder_full_with_any_features() -> BuilderFull<AnyFeatures> {
assert_initialized_main_thread!();
BuilderFull::new_with_any_features()
BuilderFull::with_any_features()
}
pub fn new_empty() -> Self {
@ -669,7 +669,7 @@ impl BuilderFull<SomeFeatures> {
}
}
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<SomeFeatures> {
}
impl BuilderFull<AnyFeatures> {
fn new_with_any_features() -> Self {
fn with_any_features() -> Self {
BuilderFull {
caps: Caps::new_empty(),
features: Some(CapsFeatures::new_any()),

View file

@ -30,7 +30,7 @@ impl GhostPad {
}
}
pub fn new_from_template<Q: IsA<Pad>>(
pub fn from_template<Q: IsA<Pad>>(
name: Option<&str>,
target: &Q,
templ: &PadTemplate,

View file

@ -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(

View file

@ -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<PadTemplate, glib::BoolError> {

View file

@ -42,7 +42,7 @@ impl Promise {
unsafe { from_glib_full(gst_sys::gst_promise_new()) }
}
pub fn new_with_change_func<F>(func: F) -> Promise
pub fn with_change_func<F>(func: F) -> Promise
where
F: FnOnce(Result<Option<&StructureRef>, 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();
});

View file

@ -298,10 +298,10 @@ impl<T: Copy> IntRange<T> {
impl IntRange<i32> {
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<i32> {
impl IntRange<i64> {
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<i32> {
impl From<(i32, i32, i32)> for IntRange<i32> {
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<i64> {
impl From<(i64, i64, i64)> for IntRange<i64> {
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<i32> {
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<i64> {
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)
}
}

View file

@ -345,7 +345,7 @@ mod tests {
assert_eq!(r#"{"min":[1,3],"max":[1,2]}"#.to_owned(), res);
// IntRange
let int_range = IntRange::<i32>::new_with_step(0, 42, 21);
let int_range = IntRange::<i32>::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::<i32>::new_with_step(0, 42, 21);
let int_range = IntRange::<i32>::with_step(0, 42, 21);
let int_range_ser = ron::ser::to_string(&int_range).unwrap();
let int_range_de: IntRange<i32> = ron::de::from_str(int_range_ser.as_str()).unwrap();
assert_eq!(int_range_de.min(), int_range.min());