Skip to content

Commit 883d630

Browse files
committed
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.
1 parent cc97e01 commit 883d630

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

glib/src/object.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,11 +1750,13 @@ pub trait ObjectExt: ObjectType {
17501750
#[doc(alias = "g_object_get_property")]
17511751
fn property_value(&self, property_name: &str) -> Value;
17521752

1753+
// rustdoc-stripper-ignore-next
1754+
/// Check if the object has a property `property_name`.
1755+
fn has_property(&self, property_name: &str) -> bool;
1756+
17531757
// rustdoc-stripper-ignore-next
17541758
/// Check if the object has a property `property_name` of the given `type_`.
1755-
///
1756-
/// If no type is provided then only the existence of the property is checked.
1757-
fn has_property(&self, property_name: &str, type_: Option<Type>) -> bool;
1759+
fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool;
17581760

17591761
// rustdoc-stripper-ignore-next
17601762
/// Get the type of the property `property_name` of this object.
@@ -2455,8 +2457,13 @@ impl<T: ObjectType> ObjectExt for T {
24552457
}
24562458
}
24572459

2458-
fn has_property(&self, property_name: &str, type_: Option<Type>) -> bool {
2459-
self.object_class().has_property(property_name, type_)
2460+
fn has_property(&self, property_name: &str) -> bool {
2461+
self.object_class().has_property(property_name)
2462+
}
2463+
2464+
fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool {
2465+
self.object_class()
2466+
.has_property_with_type(property_name, type_)
24602467
}
24612468

24622469
fn property_type(&self, property_name: &str) -> Option<Type> {
@@ -3316,16 +3323,15 @@ fn validate_signal_arguments(type_: Type, signal_query: &SignalQuery, args: &mut
33163323
pub unsafe trait ObjectClassExt {
33173324
// rustdoc-stripper-ignore-next
33183325
/// Check if the object class has a property `property_name` of the given `type_`.
3319-
///
3320-
/// If no type is provided then only the existence of the property is checked.
3321-
fn has_property(&self, property_name: &str, type_: Option<Type>) -> bool {
3322-
let ptype = self.property_type(property_name);
3326+
fn has_property(&self, property_name: &str) -> bool {
3327+
self.find_property(property_name).is_some()
3328+
}
33233329

3324-
match (ptype, type_) {
3325-
(None, _) => false,
3326-
(Some(_), None) => true,
3327-
(Some(ptype), Some(type_)) => ptype == type_,
3328-
}
3330+
// rustdoc-stripper-ignore-next
3331+
/// Check if the object class has a property `property_name` of the given `type_`.
3332+
fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool {
3333+
self.property_type(property_name)
3334+
.is_some_and(|ptype| ptype == type_)
33293335
}
33303336

33313337
// rustdoc-stripper-ignore-next
@@ -4262,17 +4268,16 @@ impl<T: IsInterface> Interface<T> {
42624268

42634269
impl<T: IsA<Object> + IsInterface> Interface<T> {
42644270
// rustdoc-stripper-ignore-next
4265-
/// Check if this interface has a property `property_name` of the given `type_`.
4266-
///
4267-
/// If no type is provided then only the existence of the property is checked.
4268-
pub fn has_property(&self, property_name: &str, type_: Option<Type>) -> bool {
4269-
let ptype = self.property_type(property_name);
4271+
/// Check if the interface has a property `property_name` of the given `type_`.
4272+
pub fn has_property(&self, property_name: &str) -> bool {
4273+
self.find_property(property_name).is_some()
4274+
}
42704275

4271-
match (ptype, type_) {
4272-
(None, _) => false,
4273-
(Some(_), None) => true,
4274-
(Some(ptype), Some(type_)) => ptype == type_,
4275-
}
4276+
// rustdoc-stripper-ignore-next
4277+
/// Check if the interface has a property `property_name` of the given `type_`.
4278+
pub fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool {
4279+
self.property_type(property_name)
4280+
.is_some_and(|ptype| ptype == type_)
42764281
}
42774282

42784283
// rustdoc-stripper-ignore-next

0 commit comments

Comments
 (0)