Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glib: Remove type parameter from Object::has_property() and add separate has_property_with_type() and check for subtypes #1565

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions glib/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
subclass::{prelude::*, SignalId, SignalQuery},
thread_guard::thread_id,
translate::*,
value::FromValue,

Check failure on line 16 in glib/src/object.rs

View workflow job for this annotation

GitHub Actions / build

unresolved import `crate::value::FromValue`
Closure, PtrSlice, RustClosure, SignalHandlerId, Type, Value,
};

Expand Down Expand Up @@ -1750,11 +1750,13 @@
#[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<Type>) -> 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.
Expand Down Expand Up @@ -2455,8 +2457,13 @@
}
}

fn has_property(&self, property_name: &str, type_: Option<Type>) -> 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<Type> {
Expand Down Expand Up @@ -3316,16 +3323,16 @@
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<Type>) -> 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_`
/// or a subtype of it.
fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool {
self.property_type(property_name)
.is_some_and(|ptype| ptype.is_a(type_))
}

// rustdoc-stripper-ignore-next
Expand Down Expand Up @@ -4262,17 +4269,17 @@

impl<T: IsA<Object> + IsInterface> Interface<T> {
// 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<Type>) -> 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_`
/// or a subtype of it.
pub fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool {
self.property_type(property_name)
.is_some_and(|ptype| ptype.is_a(type_))
}

// rustdoc-stripper-ignore-next
Expand Down Expand Up @@ -4394,7 +4401,7 @@

// If the value type is not a GObject or subtype of GObject then there's a mismatch.
if gobject_ffi::g_type_is_a(type_, gobject_ffi::G_TYPE_OBJECT) == ffi::GFALSE {
return Err(crate::value::ValueTypeMismatchError::new(

Check failure on line 4404 in glib/src/object.rs

View workflow job for this annotation

GitHub Actions / build

failed to resolve: could not find `ValueTypeMismatchError` in `value`
Type::from_glib(type_),
T::static_type(),
)
Expand All @@ -4414,7 +4421,7 @@
if gobject_ffi::g_type_is_a(type_, requested_type) != ffi::GFALSE {
Ok(())
} else {
Err(crate::value::ValueTypeMismatchError::new(

Check failure on line 4424 in glib/src/object.rs

View workflow job for this annotation

GitHub Actions / build

failed to resolve: could not find `ValueTypeMismatchError` in `value`
Type::from_glib(type_),
T::static_type(),
)
Expand Down
Loading