gst: deprecate maybe_field() setters in favor of field_if_some()

Some builder convenience setters where added to work with `Option`al values.
This is the case for the `Pad` builder setter `maybe_name()` which was
introduced as part of [this MR].

Then [more convenience setters] were discussed and [it was decided] to use
`field_if_some()` instead of `maybe_field()`. Existing `maybe_field()`s were
kept for backward compatibility. This commit marks them as deprecated,
referring to the matching `field_if_some()`.

[this MR]: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1255
[more convenience setters]: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/499
[it was decided]: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/499#note_2364820

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1592>
This commit is contained in:
François Laignel 2024-11-14 11:46:24 +01:00
parent 3f1909d828
commit 5ab9c5a203
2 changed files with 9 additions and 7 deletions

View file

@ -103,7 +103,7 @@ impl GhostPad {
/// i.e. if it's not a wildcard-name containing `%u`, `%s` or `%d`,
/// the `GhostPad` will automatically be named after the `name_template`.
///
/// Use [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::maybe_name`](crate::PadBuilder::maybe_name)
/// Use [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::name_if_some`](crate::PadBuilder::name_if_some)
/// to specify a different name.
///
/// Use [`generated_name()`](crate::PadBuilder::generated_name`) to keep the `gst::Object`
@ -143,7 +143,7 @@ impl GhostPad {
/// i.e. if it's not a wildcard-name containing `%u`, `%s` or `%d`,
/// the `GhostPad` will automatically be named after the `name_template`.
///
/// Use [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::maybe_name`](crate::PadBuilder::maybe_name)
/// Use [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::name_if_some`](crate::PadBuilder::name_if_some)
/// to specify a different name.
///
/// Use [`generated_name()`](crate::PadBuilder::generated_name`) to keep the `gst::Object`
@ -177,7 +177,7 @@ impl GhostPad {
///
/// The `GhostPad` will automatically be named after the `target` `name`.
///
/// Use [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::maybe_name`](crate::PadBuilder::maybe_name)
/// Use [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::name_if_some`](crate::PadBuilder::name_if_some)
/// to specify a different name.
///
/// Use [`generated_name()`](crate::PadBuilder::generated_name`) to keep the `gst::Object`
@ -201,7 +201,7 @@ impl GhostPad {
///
/// If the `name_template` is a wildcard-name, then the `target` `name` is used,
/// if it is compatible. Otherwise, a specific name must be provided using
/// [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::maybe_name`](crate::PadBuilder::maybe_name).
/// [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::name_if_some`](crate::PadBuilder::name_if_some).
///
/// Use [`generated_name()`](crate::PadBuilder::generated_name`) to keep the `gst::Object`
/// automatically generated unique name.
@ -224,7 +224,7 @@ impl GhostPad {
///
/// If the `name_template` is a wildcard-name, then the `target` `name` is used,
/// if it is compatible. Otherwise, a specific name must be provided using
/// [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::maybe_name`](crate::PadBuilder::maybe_name).
/// [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::name_if_some`](crate::PadBuilder::name_if_some).
///
/// Use [`generated_name()`](crate::PadBuilder::generated_name`) to keep the `gst::Object`
/// automatically generated unique name.
@ -710,7 +710,7 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
///
/// If the `name_template` is a wildcard-name, then the `target` `name` is used,
/// if it is compatible. Otherwise, a specific name must be provided using
/// [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::maybe_name`](crate::PadBuilder::maybe_name).
/// [`PadBuilder::name`](crate::PadBuilder::name) or [`PadBuilder::name_if_some`](crate::PadBuilder::name_if_some).
///
/// Use [`generated_name()`](crate::PadBuilder::generated_name`) to keep the `gst::Object`
/// automatically generated unique name.

View file

@ -1741,6 +1741,7 @@ impl<T: IsA<Pad> + IsA<glib::Object> + glib::object::IsClass> PadBuilder<T> {
///
/// This method is convenient when the `name` is provided as an `Option`.
/// If the `name` is `None`, this has no effect.
#[deprecated = "use `name_if_some()` instead"]
pub fn maybe_name<N: Into<String>>(self, name: Option<N>) -> Self {
if let Some(name) = name {
self.name(name)
@ -2104,7 +2105,7 @@ impl<T: IsA<Pad> + IsA<glib::Object> + glib::object::IsClass> PadBuilder<T> {
/// Panics if the [`Pad`] was built from a [`PadTemplate`](crate::PadTemplate)
/// with a wildcard-name `name_template` (i.e. containing `%u`, `%s` or `%d`)
/// and no specific `name` was provided using [`PadBuilder::name`]
/// or [`PadBuilder::maybe_name`], or for [`GhostPad`s](crate::GhostPad),
/// or [`PadBuilder::name_if_some`], or for [`GhostPad`s](crate::GhostPad),
/// by defining a `target`.
///
/// Use [`generated_name()`](crate::PadBuilder::generated_name`) to keep the `gst::Object`
@ -2665,6 +2666,7 @@ mod tests {
}
#[test]
#[allow(deprecated)] // maybe_name() is deprecated
fn naming() {
crate::init().unwrap();