gstreamer: Mark ParamSpec constructors as deprecated in favour of the builders

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1196>
This commit is contained in:
Sebastian Dröge 2023-01-21 19:44:12 +02:00
parent 24a16a43b6
commit 257a049673

View file

@ -42,6 +42,7 @@ impl ParamSpecFraction {
ParamSpecFractionBuilder::new(name)
}
#[deprecated = "Use builder() instead"]
#[allow(clippy::new_ret_no_self)]
#[doc(alias = "gst_param_spec_fraction")]
pub fn new<'a>(
@ -54,6 +55,18 @@ impl ParamSpecFraction {
flags: glib::ParamFlags,
) -> glib::ParamSpec {
assert_initialized_main_thread!();
unsafe { Self::new_unchecked(name, nick, blurb, min, max, default, flags) }
}
unsafe fn new_unchecked<'a>(
name: &str,
nick: impl Into<Option<&'a str>>,
blurb: impl Into<Option<&'a str>>,
min: crate::Fraction,
max: crate::Fraction,
default: crate::Fraction,
flags: glib::ParamFlags,
) -> glib::ParamSpec {
unsafe {
from_glib_none(ffi::gst_param_spec_fraction(
name.to_glib_none().0,
@ -127,7 +140,7 @@ pub struct ParamSpecFractionBuilder<'a> {
impl<'a> ParamSpecFractionBuilder<'a> {
fn new(name: &'a str) -> Self {
skip_assert_initialized!();
assert_initialized_main_thread!();
Self {
name,
..Default::default()
@ -157,7 +170,8 @@ impl<'a> ParamSpecFractionBuilder<'a> {
#[must_use]
pub fn build(self) -> ParamSpec {
ParamSpecFraction::new(
unsafe {
ParamSpecFraction::new_unchecked(
self.name,
self.nick.unwrap_or(self.name),
self.blurb.unwrap_or(self.name),
@ -170,6 +184,7 @@ impl<'a> ParamSpecFractionBuilder<'a> {
self.flags,
)
}
}
}
impl<'a> glib::prelude::ParamSpecBuilderExt<'a> for ParamSpecFractionBuilder<'a> {
@ -229,6 +244,7 @@ impl ParamSpecArray {
#[allow(clippy::new_ret_no_self)]
#[doc(alias = "gst_param_spec_array")]
#[deprecated = "Use builder() instead"]
pub fn new<'a>(
name: &str,
nick: impl Into<Option<&'a str>>,
@ -237,6 +253,17 @@ impl ParamSpecArray {
flags: glib::ParamFlags,
) -> glib::ParamSpec {
assert_initialized_main_thread!();
unsafe { Self::new_unchecked(name, nick, blurb, element_spec, flags) }
}
unsafe fn new_unchecked<'a>(
name: &str,
nick: impl Into<Option<&'a str>>,
blurb: impl Into<Option<&'a str>>,
element_spec: Option<&glib::ParamSpec>,
flags: glib::ParamFlags,
) -> glib::ParamSpec {
unsafe {
from_glib_none(ffi::gst_param_spec_array(
name.to_glib_none().0,
@ -292,7 +319,7 @@ pub struct ParamSpecArrayBuilder<'a> {
impl<'a> ParamSpecArrayBuilder<'a> {
fn new(name: &'a str) -> Self {
skip_assert_initialized!();
assert_initialized_main_thread!();
Self {
name,
..Default::default()
@ -308,7 +335,8 @@ impl<'a> ParamSpecArrayBuilder<'a> {
#[must_use]
pub fn build(self) -> ParamSpec {
ParamSpecArray::new(
unsafe {
ParamSpecArray::new_unchecked(
self.name,
self.nick.unwrap_or(self.name),
self.blurb.unwrap_or(self.name),
@ -316,6 +344,7 @@ impl<'a> ParamSpecArrayBuilder<'a> {
self.flags,
)
}
}
}
impl<'a> glib::prelude::ParamSpecBuilderExt<'a> for ParamSpecArrayBuilder<'a> {
@ -388,6 +417,7 @@ mod tests {
use super::*;
#[test]
#[allow(deprecated)]
fn test_trait() {
crate::init().unwrap();