Skip to content

Commit

Permalink
Use rust 1.79 implied supertraits to simplify trait bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Oct 5, 2024
1 parent 6224359 commit 1aaa566
Show file tree
Hide file tree
Showing 24 changed files with 209 additions and 795 deletions.
48 changes: 9 additions & 39 deletions gdk-pixbuf/src/subclass/pixbuf_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ use glib::{prelude::*, subclass::prelude::*, translate::*};

use crate::{ffi, Pixbuf, PixbufAnimation, PixbufAnimationIter};

pub trait PixbufAnimationImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufAnimation>,
pub trait PixbufAnimationImpl:
ObjectImpl + ObjectSubclass<Type: IsA<glib::Object> + IsA<PixbufAnimation>>
{
fn is_static_image(&self) -> bool {
self.parent_is_static_image()
Expand All @@ -35,11 +33,7 @@ where
}
}

pub trait PixbufAnimationImplExt: ObjectSubclass + PixbufAnimationImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
pub trait PixbufAnimationImplExt: PixbufAnimationImpl {
fn parent_is_static_image(&self) -> bool {
unsafe {
let data = Self::type_data();
Expand Down Expand Up @@ -119,18 +113,9 @@ where
}
}

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

unsafe impl<T: PixbufAnimationImpl> IsSubclassable<T> for PixbufAnimation
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
unsafe impl<T: PixbufAnimationImpl> IsSubclassable<T> for PixbufAnimation {
fn class_init(class: &mut ::glib::Class<Self>) {
Self::parent_class_init::<T>(class);

Expand All @@ -144,11 +129,7 @@ where

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>,
{
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand All @@ -159,10 +140,7 @@ unsafe extern "C" fn animation_get_size<T: PixbufAnimationImpl>(
ptr: *mut ffi::GdkPixbufAnimation,
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() {
return;
}
Expand All @@ -181,11 +159,7 @@ unsafe extern "C" fn animation_get_size<T: PixbufAnimationImpl>(

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>,
{
) -> *mut ffi::GdkPixbuf {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand Down Expand Up @@ -215,11 +189,7 @@ where
unsafe extern "C" fn animation_get_iter<T: PixbufAnimationImpl>(
ptr: *mut ffi::GdkPixbufAnimation,
start_time_ptr: *const glib::ffi::GTimeVal,
) -> *mut ffi::GdkPixbufAnimationIter
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
) -> *mut ffi::GdkPixbufAnimationIter {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand Down
49 changes: 9 additions & 40 deletions gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ use glib::{prelude::*, subclass::prelude::*, translate::*};

use crate::{ffi, Pixbuf, PixbufAnimationIter};

pub trait PixbufAnimationIterImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
pub trait PixbufAnimationIterImpl:
ObjectImpl + ObjectSubclass<Type: IsA<glib::Object> + IsA<PixbufAnimationIter>>
{
// rustdoc-stripper-ignore-next
/// Time in milliseconds, returning `None` implies showing the same pixbuf forever.
Expand All @@ -36,11 +34,7 @@ where
}
}

pub trait PixbufAnimationIterImplExt: ObjectSubclass + PixbufAnimationIterImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
pub trait PixbufAnimationIterImplExt: PixbufAnimationIterImpl {
fn parent_delay_time(&self) -> Option<Duration> {
unsafe {
let data = Self::type_data();
Expand Down Expand Up @@ -124,18 +118,9 @@ where
}
}

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

unsafe impl<T: PixbufAnimationIterImpl> IsSubclassable<T> for PixbufAnimationIter
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
unsafe impl<T: PixbufAnimationIterImpl> IsSubclassable<T> for PixbufAnimationIter {
fn class_init(class: &mut ::glib::Class<Self>) {
Self::parent_class_init::<T>(class);

Expand All @@ -149,11 +134,7 @@ where

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>,
{
) -> i32 {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand All @@ -162,11 +143,7 @@ where

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>,
{
) -> *mut ffi::GdkPixbuf {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand All @@ -182,11 +159,7 @@ where

unsafe extern "C" fn animation_iter_on_currently_loading_frame<T: PixbufAnimationIterImpl>(
ptr: *mut ffi::GdkPixbufAnimationIter,
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand All @@ -196,11 +169,7 @@ where
unsafe extern "C" fn animation_iter_advance<T: PixbufAnimationIterImpl>(
ptr: *mut ffi::GdkPixbufAnimationIter,
current_time_ptr: *const glib::ffi::GTimeVal,
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand Down
47 changes: 9 additions & 38 deletions gdk-pixbuf/src/subclass/pixbuf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ use glib::{prelude::*, subclass::prelude::*, translate::*};

use crate::{ffi, PixbufLoader};

pub trait PixbufLoaderImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufLoader>,
pub trait PixbufLoaderImpl:
ObjectImpl + ObjectSubclass<Type: IsA<glib::Object> + IsA<PixbufLoader>>
{
fn size_prepared(&self, width: i32, height: i32) {
self.parent_size_prepared(width, height)
Expand All @@ -29,11 +27,7 @@ where
}
}

pub trait PixbufLoaderImplExt: ObjectSubclass + PixbufLoaderImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
pub trait PixbufLoaderImplExt: PixbufLoaderImpl {
fn parent_size_prepared(&self, width: i32, height: i32) {
unsafe {
let data = Self::type_data();
Expand Down Expand Up @@ -99,18 +93,9 @@ where
}
}

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

unsafe impl<T: PixbufLoaderImpl> IsSubclassable<T> for PixbufLoader
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
unsafe impl<T: PixbufLoaderImpl> IsSubclassable<T> for PixbufLoader {
fn class_init(class: &mut ::glib::Class<Self>) {
Self::parent_class_init::<T>(class);

Expand All @@ -126,21 +111,14 @@ unsafe extern "C" fn loader_size_prepared<T: PixbufLoaderImpl>(
ptr: *mut ffi::GdkPixbufLoader,
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);
let imp = instance.imp();

imp.size_prepared(width, height)
}

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>,
{
unsafe extern "C" fn loader_area_prepared<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader) {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand All @@ -153,21 +131,14 @@ unsafe extern "C" fn loader_area_updated<T: PixbufLoaderImpl>(
y: i32,
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);
let imp = instance.imp();

imp.area_updated(x, y, width, height)
}

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>,
{
unsafe extern "C" fn loader_closed<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader) {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand Down
Loading

0 comments on commit 1aaa566

Please sign in to comment.