Skip to content

Commit c940ecd

Browse files
authored
Merge pull request #1565 from sdroege/has-property-rename
glib: Remove type parameter from `Object::has_property()` and add separate `has_property_with_type()` and check for subtypes
2 parents c9f969c + 722ad59 commit c940ecd

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

glib/src/object.rs

Lines changed: 31 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,16 @@ 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+
/// or a subtype of it.
3333+
fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool {
3334+
self.property_type(property_name)
3335+
.is_some_and(|ptype| ptype.is_a(type_))
33293336
}
33303337

33313338
// rustdoc-stripper-ignore-next
@@ -4262,17 +4269,17 @@ impl<T: IsInterface> Interface<T> {
42624269

42634270
impl<T: IsA<Object> + IsInterface> Interface<T> {
42644271
// 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);
4272+
/// Check if the interface has a property `property_name` of the given `type_`.
4273+
pub fn has_property(&self, property_name: &str) -> bool {
4274+
self.find_property(property_name).is_some()
4275+
}
42704276

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

42784285
// rustdoc-stripper-ignore-next

0 commit comments

Comments
 (0)