From 883d63004545148beda720b204bc3965c1ed91ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 6 Nov 2024 10:17:00 +0200 Subject: [PATCH] glib: Remove type parameter from `Object::has_property()` and add separate `has_property_with_type()` Most of the time the property type is not interesting and the `None` makes the code harder to understand. Having a separate, more descriptive function for also checking the type seems better. --- glib/src/object.rs | 53 +++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/glib/src/object.rs b/glib/src/object.rs index 9eefb0dc591a..9d722b4e7e33 100644 --- a/glib/src/object.rs +++ b/glib/src/object.rs @@ -1750,11 +1750,13 @@ pub trait ObjectExt: ObjectType { #[doc(alias = "g_object_get_property")] fn property_value(&self, property_name: &str) -> Value; + // rustdoc-stripper-ignore-next + /// Check if the object has a property `property_name`. + fn has_property(&self, property_name: &str) -> bool; + // rustdoc-stripper-ignore-next /// Check if the object has a property `property_name` of the given `type_`. - /// - /// If no type is provided then only the existence of the property is checked. - fn has_property(&self, property_name: &str, type_: Option) -> bool; + fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool; // rustdoc-stripper-ignore-next /// Get the type of the property `property_name` of this object. @@ -2455,8 +2457,13 @@ impl ObjectExt for T { } } - fn has_property(&self, property_name: &str, type_: Option) -> bool { - self.object_class().has_property(property_name, type_) + fn has_property(&self, property_name: &str) -> bool { + self.object_class().has_property(property_name) + } + + fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool { + self.object_class() + .has_property_with_type(property_name, type_) } fn property_type(&self, property_name: &str) -> Option { @@ -3316,16 +3323,15 @@ fn validate_signal_arguments(type_: Type, signal_query: &SignalQuery, args: &mut pub unsafe trait ObjectClassExt { // rustdoc-stripper-ignore-next /// Check if the object class has a property `property_name` of the given `type_`. - /// - /// If no type is provided then only the existence of the property is checked. - fn has_property(&self, property_name: &str, type_: Option) -> bool { - let ptype = self.property_type(property_name); + fn has_property(&self, property_name: &str) -> bool { + self.find_property(property_name).is_some() + } - match (ptype, type_) { - (None, _) => false, - (Some(_), None) => true, - (Some(ptype), Some(type_)) => ptype == type_, - } + // rustdoc-stripper-ignore-next + /// Check if the object class has a property `property_name` of the given `type_`. + fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool { + self.property_type(property_name) + .is_some_and(|ptype| ptype == type_) } // rustdoc-stripper-ignore-next @@ -4262,17 +4268,16 @@ impl Interface { impl + IsInterface> Interface { // rustdoc-stripper-ignore-next - /// Check if this interface has a property `property_name` of the given `type_`. - /// - /// If no type is provided then only the existence of the property is checked. - pub fn has_property(&self, property_name: &str, type_: Option) -> bool { - let ptype = self.property_type(property_name); + /// Check if the interface has a property `property_name` of the given `type_`. + pub fn has_property(&self, property_name: &str) -> bool { + self.find_property(property_name).is_some() + } - match (ptype, type_) { - (None, _) => false, - (Some(_), None) => true, - (Some(ptype), Some(type_)) => ptype == type_, - } + // rustdoc-stripper-ignore-next + /// Check if the interface has a property `property_name` of the given `type_`. + pub fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool { + self.property_type(property_name) + .is_some_and(|ptype| ptype == type_) } // rustdoc-stripper-ignore-next