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