Skip to content

Use rust 1.79 implied supertraits to simplify trait bounds #1529

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

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- stable
- beta
- nightly
- "1.70.0"
- "1.80.0"
conf:
- { name: "cairo", features: "png,pdf,svg,ps,use_glib,v1_18,freetype,script,xcb,xlib,win32-surface", nightly: "--features 'png,pdf,svg,ps,use_glib,v1_18,freetype,script,xcb,xlib,win32-surface'", test_sys: true }
- { name: "gdk-pixbuf", features: "v2_42", nightly: "--all-features", test_sys: true }
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
- stable
- beta
- nightly
- "1.70.0"
- "1.80.0"
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
Expand Down
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ authors = ["The gtk-rs Project Developers"]
version = "0.21.0"
repository = "https://github.com/gtk-rs/gtk-rs-core"
license = "MIT"
exclude = [
"gir-files/*",
]
exclude = ["gir-files/*"]
edition = "2021"
rust-version = "1.70"
rust-version = "1.80"

[workspace.dependencies]
libc = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ information about each crate, please refer to their `README.md` file in their di

## Minimum supported Rust version

Currently, the minimum supported Rust version is `1.70.0`.
Currently, the minimum supported Rust version is `1.80.0`.

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion cairo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Cairo __1.14__ is the lowest supported version for the underlying library.

## Minimum supported Rust version

Currently, the minimum supported Rust version is `1.70.0`.
Currently, the minimum supported Rust version is `1.80.0`.

## Default-on features

Expand Down
16 changes: 2 additions & 14 deletions examples/virtual_methods/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,7 @@ impl Default for Cat {
///
/// By convention we still create an empty `CatImpl` trait, this allows us to add
/// 'protected' cat methods only available to be called by other Cats later.
pub trait CatImpl: PetImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Pet>,
<Self as ObjectSubclass>::Type: IsA<Cat>,
{
}
pub trait CatImpl: PetImpl + ObjectSubclass<Type: IsA<Cat>> {}

/// To make this class subclassable we need to implement IsSubclassable
unsafe impl<Obj: CatImpl + PetImpl> IsSubclassable<Obj> for Cat
where
<Obj as ObjectSubclass>::Type: IsA<glib::Object>,
<Obj as ObjectSubclass>::Type: IsA<Pet>,
<Obj as ObjectSubclass>::Type: IsA<Cat>,
{
}
unsafe impl<Obj: CatImpl + PetImpl> IsSubclassable<Obj> for Cat {}
25 changes: 4 additions & 21 deletions examples/virtual_methods/pet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ pub trait PetExt: IsA<Pet> {
impl<T: IsA<Pet>> PetExt for T {}

/// The `PetImpl` trait contains overridable virtual function definitions for [`Pet`] objects.
pub trait PetImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Pet>,
{
pub trait PetImpl: ObjectImpl + ObjectSubclass<Type: IsA<Pet>> {
/// Default implementation of a virtual method.
///
/// This always calls into the implementation of the parent class so that if
Expand All @@ -152,11 +148,7 @@ where
/// The `PetImplExt` trait contains non-overridable methods for subclasses to use.
///
/// These are supposed to be called only from inside implementations of `Pet` subclasses.
pub trait PetImplExt: PetImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Pet>,
{
pub trait PetImplExt: PetImpl {
/// Chains up to the parent implementation of [`PetImpl::pet`]
fn parent_pet(&self) -> bool {
let data = Self::type_data();
Expand All @@ -177,19 +169,10 @@ where
}

/// The `PetImplExt` trait is implemented for all subclasses that have [`Pet`] in the class hierarchy
impl<T: PetImpl> PetImplExt for T
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Pet>,
{
}
impl<T: PetImpl> PetImplExt for T {}

/// To make this class subclassable we need to implement IsSubclassable
unsafe impl<Obj: PetImpl> IsSubclassable<Obj> for Pet
where
<Obj as ObjectSubclass>::Type: IsA<glib::Object>,
<Obj as ObjectSubclass>::Type: IsA<Pet>,
{
unsafe impl<Obj: PetImpl> IsSubclassable<Obj> for Pet {
/// Override the virtual method function pointers in subclasses to call directly into the
/// `PetImpl` of the subclass.
///
Expand Down
25 changes: 4 additions & 21 deletions examples/virtual_methods/purrable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ pub trait PurrableExt: IsA<Purrable> {
impl<T: IsA<Purrable>> PurrableExt for T {}

/// The `PurrableImpl` trait contains virtual function definitions for [`Purrable`] objects.
pub trait PurrableImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Purrable>,
{
pub trait PurrableImpl: ObjectImpl + ObjectSubclass<Type: IsA<Purrable>> {
/// Return the current purring status.
///
/// The default implementation chains up to the parent implementation,
Expand All @@ -100,11 +96,7 @@ where
/// The `PurrableImplExt` trait contains non-overridable methods for subclasses to use.
///
/// These are supposed to be called only from inside implementations of `Pet` subclasses.
pub trait PurrableImplExt: PurrableImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Purrable>,
{
pub trait PurrableImplExt: PurrableImpl {
/// Chains up to the parent implementation of [`PurrableExt::is_purring`]
fn parent_is_purring(&self) -> bool {
let data = Self::type_data();
Expand All @@ -117,19 +109,10 @@ where
}

/// The `PurrableImplExt` trait is implemented for all classes that implement [`Purrable`].
impl<T: PurrableImpl> PurrableImplExt for T
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Purrable>,
{
}
impl<T: PurrableImpl> PurrableImplExt for T {}

/// To make this interface implementable we need to implement [`IsImplementable`]
unsafe impl<Obj: PurrableImpl> IsImplementable<Obj> for Purrable
where
<Obj as ObjectSubclass>::Type: IsA<glib::Object>,
<Obj as ObjectSubclass>::Type: IsA<Purrable>,
{
unsafe impl<Obj: PurrableImpl> IsImplementable<Obj> for Purrable {
fn interface_init(iface: &mut glib::Interface<Self>) {
let klass = iface.as_mut();

Expand Down
2 changes: 1 addition & 1 deletion gdk-pixbuf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GDK-PixBuf __2.36.8__ is the lowest supported version for the underlying library

## Minimum supported Rust version

Currently, the minimum supported Rust version is `1.70.0`.
Currently, the minimum supported Rust version is `1.80.0`.

## Documentation

Expand Down
48 changes: 8 additions & 40 deletions gdk-pixbuf/src/subclass/pixbuf_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ 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<PixbufAnimation>> {
fn is_static_image(&self) -> bool {
self.parent_is_static_image()
}
Expand All @@ -35,11 +31,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 +111,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 +127,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 +138,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 +157,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 +187,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<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
Loading
Loading