Skip to content

Commit

Permalink
Add IsA<Object> trait bound to Impl traits
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Oct 3, 2024
1 parent cbdbf60 commit 7e1f8dc
Show file tree
Hide file tree
Showing 25 changed files with 356 additions and 77 deletions.
13 changes: 11 additions & 2 deletions gdk-pixbuf/src/subclass/pixbuf_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{ffi, Pixbuf, PixbufAnimation, PixbufAnimationIter};

pub trait PixbufAnimationImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
fn is_static_image(&self) -> bool {
Expand All @@ -36,6 +37,7 @@ where

pub trait PixbufAnimationImplExt: ObjectSubclass + PixbufAnimationImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
fn parent_is_static_image(&self) -> bool {
Expand Down Expand Up @@ -117,13 +119,16 @@ where
}
}

impl<T: PixbufAnimationImpl> PixbufAnimationImplExt for T where
<Self as ObjectSubclass>::Type: IsA<PixbufAnimation>
impl<T: PixbufAnimationImpl> PixbufAnimationImplExt for T
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
}

unsafe impl<T: PixbufAnimationImpl> IsSubclassable<T> for PixbufAnimation
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
fn class_init(class: &mut ::glib::Class<Self>) {
Expand All @@ -141,6 +146,7 @@ unsafe extern "C" fn animation_is_static_image<T: PixbufAnimationImpl>(
ptr: *mut ffi::GdkPixbufAnimation,
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
let instance = &*(ptr as *mut T::Instance);
Expand All @@ -154,6 +160,7 @@ unsafe extern "C" fn animation_get_size<T: PixbufAnimationImpl>(
width_ptr: *mut libc::c_int,
height_ptr: *mut libc::c_int,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
if width_ptr.is_null() && height_ptr.is_null() {
Expand All @@ -176,6 +183,7 @@ unsafe extern "C" fn animation_get_static_image<T: PixbufAnimationImpl>(
ptr: *mut ffi::GdkPixbufAnimation,
) -> *mut ffi::GdkPixbuf
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
let instance = &*(ptr as *mut T::Instance);
Expand Down Expand Up @@ -209,6 +217,7 @@ unsafe extern "C" fn animation_get_iter<T: PixbufAnimationImpl>(
start_time_ptr: *const glib::ffi::GTimeVal,
) -> *mut ffi::GdkPixbufAnimationIter
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
let instance = &*(ptr as *mut T::Instance);
Expand Down
13 changes: 11 additions & 2 deletions gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{ffi, Pixbuf, PixbufAnimationIter};

pub trait PixbufAnimationIterImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
// rustdoc-stripper-ignore-next
Expand All @@ -37,6 +38,7 @@ where

pub trait PixbufAnimationIterImplExt: ObjectSubclass + PixbufAnimationIterImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
fn parent_delay_time(&self) -> Option<Duration> {
Expand Down Expand Up @@ -122,13 +124,16 @@ where
}
}

impl<T: PixbufAnimationIterImpl> PixbufAnimationIterImplExt for T where
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>
impl<T: PixbufAnimationIterImpl> PixbufAnimationIterImplExt for T
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
}

unsafe impl<T: PixbufAnimationIterImpl> IsSubclassable<T> for PixbufAnimationIter
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
fn class_init(class: &mut ::glib::Class<Self>) {
Expand All @@ -146,6 +151,7 @@ unsafe extern "C" fn animation_iter_get_delay_time<T: PixbufAnimationIterImpl>(
ptr: *mut ffi::GdkPixbufAnimationIter,
) -> i32
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
let instance = &*(ptr as *mut T::Instance);
Expand All @@ -158,6 +164,7 @@ unsafe extern "C" fn animation_iter_get_pixbuf<T: PixbufAnimationIterImpl>(
ptr: *mut ffi::GdkPixbufAnimationIter,
) -> *mut ffi::GdkPixbuf
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
let instance = &*(ptr as *mut T::Instance);
Expand All @@ -177,6 +184,7 @@ unsafe extern "C" fn animation_iter_on_currently_loading_frame<T: PixbufAnimatio
ptr: *mut ffi::GdkPixbufAnimationIter,
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
let instance = &*(ptr as *mut T::Instance);
Expand All @@ -190,6 +198,7 @@ unsafe extern "C" fn animation_iter_advance<T: PixbufAnimationIterImpl>(
current_time_ptr: *const glib::ffi::GTimeVal,
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
let instance = &*(ptr as *mut T::Instance);
Expand Down
13 changes: 11 additions & 2 deletions gdk-pixbuf/src/subclass/pixbuf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{ffi, PixbufLoader};

pub trait PixbufLoaderImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
fn size_prepared(&self, width: i32, height: i32) {
Expand All @@ -30,6 +31,7 @@ where

pub trait PixbufLoaderImplExt: ObjectSubclass + PixbufLoaderImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
fn parent_size_prepared(&self, width: i32, height: i32) {
Expand Down Expand Up @@ -97,13 +99,16 @@ where
}
}

impl<T: PixbufLoaderImpl> PixbufLoaderImplExt for T where
<T as ObjectSubclass>::Type: IsA<PixbufLoader>
impl<T: PixbufLoaderImpl> PixbufLoaderImplExt for T
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
}

unsafe impl<T: PixbufLoaderImpl> IsSubclassable<T> for PixbufLoader
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
fn class_init(class: &mut ::glib::Class<Self>) {
Expand All @@ -122,6 +127,7 @@ unsafe extern "C" fn loader_size_prepared<T: PixbufLoaderImpl>(
width: i32,
height: i32,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
let instance = &*(ptr as *mut T::Instance);
Expand All @@ -132,6 +138,7 @@ unsafe extern "C" fn loader_size_prepared<T: PixbufLoaderImpl>(

unsafe extern "C" fn loader_area_prepared<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader)
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
let instance = &*(ptr as *mut T::Instance);
Expand All @@ -147,6 +154,7 @@ unsafe extern "C" fn loader_area_updated<T: PixbufLoaderImpl>(
width: i32,
height: i32,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
let instance = &*(ptr as *mut T::Instance);
Expand All @@ -157,6 +165,7 @@ unsafe extern "C" fn loader_area_updated<T: PixbufLoaderImpl>(

unsafe extern "C" fn loader_closed<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader)
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
let instance = &*(ptr as *mut T::Instance);
Expand Down
25 changes: 23 additions & 2 deletions gio/src/subclass/action_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{ffi, ActionGroup};

pub trait ActionGroupImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<ActionGroup>,
{
fn action_added(&self, action_name: &str) {
Expand Down Expand Up @@ -78,6 +79,7 @@ where

pub trait ActionGroupImplExt: ObjectSubclass + ActionGroupImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<ActionGroup>,
{
fn parent_action_added(&self, action_name: &str) {
Expand Down Expand Up @@ -342,11 +344,16 @@ where
}
}

impl<T: ActionGroupImpl> ActionGroupImplExt for T where <T as ObjectSubclass>::Type: IsA<ActionGroup>
{}
impl<T: ActionGroupImpl> ActionGroupImplExt for T
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
}

unsafe impl<T: ActionGroupImpl> IsImplementable<T> for ActionGroup
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
fn interface_init(iface: &mut glib::Interface<Self>) {
Expand Down Expand Up @@ -374,6 +381,7 @@ unsafe extern "C" fn action_group_has_action<T: ActionGroupImpl>(
action_nameptr: *const libc::c_char,
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand All @@ -388,6 +396,7 @@ unsafe extern "C" fn action_group_get_action_enabled<T: ActionGroupImpl>(
action_nameptr: *const libc::c_char,
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand All @@ -412,6 +421,7 @@ unsafe extern "C" fn action_group_get_action_parameter_type<T: ActionGroupImpl>(
action_nameptr: *const libc::c_char,
) -> *const glib::ffi::GVariantType
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand Down Expand Up @@ -444,6 +454,7 @@ unsafe extern "C" fn action_group_get_action_state_type<T: ActionGroupImpl>(
action_nameptr: *const libc::c_char,
) -> *const glib::ffi::GVariantType
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand Down Expand Up @@ -476,6 +487,7 @@ unsafe extern "C" fn action_group_get_action_state_hint<T: ActionGroupImpl>(
action_nameptr: *const libc::c_char,
) -> *mut glib::ffi::GVariant
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand Down Expand Up @@ -507,6 +519,7 @@ unsafe extern "C" fn action_group_get_action_state<T: ActionGroupImpl>(
action_nameptr: *const libc::c_char,
) -> *mut glib::ffi::GVariant
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand Down Expand Up @@ -536,6 +549,7 @@ unsafe extern "C" fn action_group_change_action_state<T: ActionGroupImpl>(
action_nameptr: *const libc::c_char,
stateptr: *mut glib::ffi::GVariant,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand All @@ -551,6 +565,7 @@ unsafe extern "C" fn action_group_activate_action<T: ActionGroupImpl>(
action_nameptr: *const libc::c_char,
parameterptr: *mut glib::ffi::GVariant,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand All @@ -565,6 +580,7 @@ unsafe extern "C" fn action_group_action_added<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand All @@ -578,6 +594,7 @@ unsafe extern "C" fn action_group_action_removed<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand All @@ -592,6 +609,7 @@ unsafe extern "C" fn action_group_action_enabled_changed<T: ActionGroupImpl>(
action_nameptr: *const libc::c_char,
enabled: glib::ffi::gboolean,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand All @@ -606,6 +624,7 @@ unsafe extern "C" fn action_group_action_state_changed<T: ActionGroupImpl>(
action_nameptr: *const libc::c_char,
stateptr: *mut glib::ffi::GVariant,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand All @@ -620,6 +639,7 @@ unsafe extern "C" fn action_group_list_actions<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
) -> *mut *mut libc::c_char
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand Down Expand Up @@ -649,6 +669,7 @@ unsafe extern "C" fn action_group_query_action<T: ActionGroupImpl>(
state: *mut *mut glib::ffi::GVariant,
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
Expand Down
Loading

0 comments on commit 7e1f8dc

Please sign in to comment.