forked from mirrors/gstreamer-rs
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:
parent
7b2fe31cc1
commit
a954c03bc0
14 changed files with 40 additions and 43 deletions
|
@ -360,18 +360,17 @@ impl App {
|
||||||
#[cfg(any(feature = "gl-egl", feature = "gl-wayland"))]
|
#[cfg(any(feature = "gl-egl", feature = "gl-wayland"))]
|
||||||
RawHandle::Egl(egl_context) => {
|
RawHandle::Egl(egl_context) => {
|
||||||
#[cfg(feature = "gl-egl")]
|
#[cfg(feature = "gl-egl")]
|
||||||
let gl_display =
|
let gl_display = if let Some(display) =
|
||||||
if let Some(display) = unsafe { windowed_context.get_egl_display() } {
|
unsafe { windowed_context.get_egl_display() }
|
||||||
unsafe { gst_gl::GLDisplayEGL::new_with_egl_display(display as usize) }
|
{
|
||||||
.unwrap()
|
unsafe { gst_gl::GLDisplayEGL::with_egl_display(display as usize) }.unwrap()
|
||||||
} else {
|
} else {
|
||||||
panic!("EGL context without EGL display");
|
panic!("EGL context without EGL display");
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(feature = "gl-egl"))]
|
#[cfg(not(feature = "gl-egl"))]
|
||||||
let gl_display = if let Some(display) = inner_window.get_wayland_display() {
|
let gl_display = if let Some(display) = inner_window.get_wayland_display() {
|
||||||
unsafe { gst_gl::GLDisplayWayland::new_with_display(display as usize) }
|
unsafe { gst_gl::GLDisplayWayland::with_display(display as usize) }.unwrap()
|
||||||
.unwrap()
|
|
||||||
} else {
|
} else {
|
||||||
panic!("Wayland window without Wayland display");
|
panic!("Wayland window without Wayland display");
|
||||||
};
|
};
|
||||||
|
@ -385,7 +384,7 @@ impl App {
|
||||||
#[cfg(feature = "gl-x11")]
|
#[cfg(feature = "gl-x11")]
|
||||||
RawHandle::Glx(glx_context) => {
|
RawHandle::Glx(glx_context) => {
|
||||||
let gl_display = if let Some(display) = inner_window.get_xlib_display() {
|
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 {
|
} else {
|
||||||
panic!("X11 window without X Display");
|
panic!("X11 window without X Display");
|
||||||
};
|
};
|
||||||
|
|
|
@ -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: &P,
|
||||||
element_sinkpad_name: Option<&str>,
|
element_sinkpad_name: Option<&str>,
|
||||||
element_srcpad_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_name: &str,
|
||||||
element_sinkpad_name: Option<&str>,
|
element_sinkpad_name: Option<&str>,
|
||||||
element_srcpad_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,
|
element_name: &str,
|
||||||
hsrc: Option<&gst::StaticPadTemplate>,
|
hsrc: Option<&gst::StaticPadTemplate>,
|
||||||
hsink: Option<&gst::StaticPadTemplate>,
|
hsink: Option<&gst::StaticPadTemplate>,
|
||||||
|
|
|
@ -14,7 +14,7 @@ use GLDisplayEGL;
|
||||||
use GLDisplayType;
|
use GLDisplayType;
|
||||||
|
|
||||||
impl GLDisplayEGL {
|
impl GLDisplayEGL {
|
||||||
pub unsafe fn new_with_egl_display(
|
pub unsafe fn with_egl_display(
|
||||||
display: uintptr_t,
|
display: uintptr_t,
|
||||||
) -> Result<GLDisplayEGL, glib::error::BoolError> {
|
) -> Result<GLDisplayEGL, glib::error::BoolError> {
|
||||||
let result = from_glib_full(gst_gl_sys::gst_gl_display_egl_new_with_egl_display(
|
let result = from_glib_full(gst_gl_sys::gst_gl_display_egl_new_with_egl_display(
|
||||||
|
|
|
@ -13,7 +13,7 @@ use libc::uintptr_t;
|
||||||
use GLDisplayWayland;
|
use GLDisplayWayland;
|
||||||
|
|
||||||
impl GLDisplayWayland {
|
impl GLDisplayWayland {
|
||||||
pub unsafe fn new_with_display(
|
pub unsafe fn with_display(
|
||||||
display: uintptr_t,
|
display: uintptr_t,
|
||||||
) -> Result<GLDisplayWayland, glib::error::BoolError> {
|
) -> Result<GLDisplayWayland, glib::error::BoolError> {
|
||||||
let result = from_glib_full(gst_gl_sys::gst_gl_display_wayland_new_with_display(
|
let result = from_glib_full(gst_gl_sys::gst_gl_display_wayland_new_with_display(
|
||||||
|
|
|
@ -13,9 +13,7 @@ use libc::uintptr_t;
|
||||||
use GLDisplayX11;
|
use GLDisplayX11;
|
||||||
|
|
||||||
impl GLDisplayX11 {
|
impl GLDisplayX11 {
|
||||||
pub unsafe fn new_with_display(
|
pub unsafe fn with_display(display: uintptr_t) -> Result<GLDisplayX11, glib::error::BoolError> {
|
||||||
display: uintptr_t,
|
|
||||||
) -> Result<GLDisplayX11, glib::error::BoolError> {
|
|
||||||
let result = from_glib_full(gst_gl_sys::gst_gl_display_x11_new_with_display(
|
let result = from_glib_full(gst_gl_sys::gst_gl_display_x11_new_with_display(
|
||||||
display as gpointer,
|
display as gpointer,
|
||||||
));
|
));
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl PlayerVideoOverlayVideoRenderer {
|
||||||
) as *mut _)
|
) 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,
|
window_handle: uintptr_t,
|
||||||
video_sink: &P,
|
video_sink: &P,
|
||||||
) -> PlayerVideoOverlayVideoRenderer {
|
) -> 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!();
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl VideoTimeCode {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
||||||
pub fn new_from_date_time(
|
pub fn from_date_time(
|
||||||
fps: gst::Fraction,
|
fps: gst::Fraction,
|
||||||
dt: &glib::DateTime,
|
dt: &glib::DateTime,
|
||||||
flags: VideoTimeCodeFlags,
|
flags: VideoTimeCodeFlags,
|
||||||
|
@ -183,13 +183,13 @@ impl ValidVideoTimeCode {
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(any(feature = "v1_16", feature = "dox"))]
|
// #[cfg(any(feature = "v1_16", feature = "dox"))]
|
||||||
// pub fn new_from_date_time(
|
// pub fn from_date_time(
|
||||||
// fps: gst::Fraction,
|
// fps: gst::Fraction,
|
||||||
// dt: &glib::DateTime,
|
// dt: &glib::DateTime,
|
||||||
// flags: VideoTimeCodeFlags,
|
// flags: VideoTimeCodeFlags,
|
||||||
// field_count: u32,
|
// field_count: u32,
|
||||||
// ) -> Option<VideoTimeCode> {
|
// ) -> 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())
|
// tc.and_then(|tc| tc.try_into().ok())
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,12 @@ impl Caps {
|
||||||
|
|
||||||
pub fn builder_full_with_features(features: CapsFeatures) -> BuilderFull<SomeFeatures> {
|
pub fn builder_full_with_features(features: CapsFeatures) -> BuilderFull<SomeFeatures> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
BuilderFull::new_with_features(features)
|
BuilderFull::with_features(features)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn builder_full_with_any_features() -> BuilderFull<AnyFeatures> {
|
pub fn builder_full_with_any_features() -> BuilderFull<AnyFeatures> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
BuilderFull::new_with_any_features()
|
BuilderFull::with_any_features()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_empty() -> Self {
|
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!();
|
skip_assert_initialized!();
|
||||||
BuilderFull {
|
BuilderFull {
|
||||||
caps: Caps::new_empty(),
|
caps: Caps::new_empty(),
|
||||||
|
@ -688,7 +688,7 @@ impl BuilderFull<SomeFeatures> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuilderFull<AnyFeatures> {
|
impl BuilderFull<AnyFeatures> {
|
||||||
fn new_with_any_features() -> Self {
|
fn with_any_features() -> Self {
|
||||||
BuilderFull {
|
BuilderFull {
|
||||||
caps: Caps::new_empty(),
|
caps: Caps::new_empty(),
|
||||||
features: Some(CapsFeatures::new_any()),
|
features: Some(CapsFeatures::new_any()),
|
||||||
|
|
|
@ -30,7 +30,7 @@ impl GhostPad {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_template<Q: IsA<Pad>>(
|
pub fn from_template<Q: IsA<Pad>>(
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
target: &Q,
|
target: &Q,
|
||||||
templ: &PadTemplate,
|
templ: &PadTemplate,
|
||||||
|
|
|
@ -50,7 +50,7 @@ use libc;
|
||||||
use gst_sys;
|
use gst_sys;
|
||||||
|
|
||||||
impl Pad {
|
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!();
|
assert_initialized_main_thread!();
|
||||||
unsafe {
|
unsafe {
|
||||||
from_glib_none(gst_sys::gst_pad_new_from_static_template(
|
from_glib_none(gst_sys::gst_pad_new_from_static_template(
|
||||||
|
|
|
@ -19,7 +19,7 @@ use gst_sys;
|
||||||
|
|
||||||
impl PadTemplate {
|
impl PadTemplate {
|
||||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
#[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_template: &StaticPadTemplate,
|
||||||
pad_type: glib::types::Type,
|
pad_type: glib::types::Type,
|
||||||
) -> Result<PadTemplate, glib::BoolError> {
|
) -> Result<PadTemplate, glib::BoolError> {
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl Promise {
|
||||||
unsafe { from_glib_full(gst_sys::gst_promise_new()) }
|
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
|
where
|
||||||
F: FnOnce(Result<Option<&StructureRef>, PromiseError>) + Send + 'static,
|
F: FnOnce(Result<Option<&StructureRef>, PromiseError>) + Send + 'static,
|
||||||
{
|
{
|
||||||
|
@ -95,7 +95,7 @@ impl Promise {
|
||||||
|
|
||||||
// We only use the channel as a convenient waker
|
// We only use the channel as a convenient waker
|
||||||
let (sender, receiver) = oneshot::channel();
|
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(());
|
let _ = sender.send(());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ mod tests {
|
||||||
::init().unwrap();
|
::init().unwrap();
|
||||||
|
|
||||||
let (sender, receiver) = channel();
|
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();
|
sender.send(res.map(|s| s.map(ToOwned::to_owned))).unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -298,10 +298,10 @@ impl<T: Copy> IntRange<T> {
|
||||||
impl IntRange<i32> {
|
impl IntRange<i32> {
|
||||||
pub fn new(min: i32, max: i32) -> Self {
|
pub fn new(min: i32, max: i32) -> Self {
|
||||||
skip_assert_initialized!();
|
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_initialized_main_thread!();
|
||||||
|
|
||||||
assert!(min <= max);
|
assert!(min <= max);
|
||||||
|
@ -314,10 +314,10 @@ impl IntRange<i32> {
|
||||||
impl IntRange<i64> {
|
impl IntRange<i64> {
|
||||||
pub fn new(min: i64, max: i64) -> Self {
|
pub fn new(min: i64, max: i64) -> Self {
|
||||||
skip_assert_initialized!();
|
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_initialized_main_thread!();
|
||||||
|
|
||||||
assert!(min <= max);
|
assert!(min <= max);
|
||||||
|
@ -337,7 +337,7 @@ impl From<(i32, i32)> for IntRange<i32> {
|
||||||
impl From<(i32, i32, i32)> for IntRange<i32> {
|
impl From<(i32, i32, i32)> for IntRange<i32> {
|
||||||
fn from((min, max, step): (i32, i32, i32)) -> Self {
|
fn from((min, max, step): (i32, i32, i32)) -> Self {
|
||||||
skip_assert_initialized!();
|
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> {
|
impl From<(i64, i64, i64)> for IntRange<i64> {
|
||||||
fn from((min, max, step): (i64, i64, i64)) -> Self {
|
fn from((min, max, step): (i64, i64, i64)) -> Self {
|
||||||
skip_assert_initialized!();
|
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 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);
|
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 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);
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -345,7 +345,7 @@ mod tests {
|
||||||
assert_eq!(r#"{"min":[1,3],"max":[1,2]}"#.to_owned(), res);
|
assert_eq!(r#"{"min":[1,3],"max":[1,2]}"#.to_owned(), res);
|
||||||
|
|
||||||
// IntRange
|
// 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());
|
let res = ron::ser::to_string_pretty(&int_range, pretty_config.clone());
|
||||||
assert_eq!(Ok("( min: 0, max: 42, step: 21,)".to_owned()), res,);
|
assert_eq!(Ok("( min: 0, max: 42, step: 21,)".to_owned()), res,);
|
||||||
|
|
||||||
|
@ -550,7 +550,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
// IntRange
|
// 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_ser = ron::ser::to_string(&int_range).unwrap();
|
||||||
let int_range_de: IntRange<i32> = ron::de::from_str(int_range_ser.as_str()).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());
|
assert_eq!(int_range_de.min(), int_range.min());
|
||||||
|
|
Loading…
Reference in a new issue