Skip to content

Commit 5ec8462

Browse files
authored
Merge pull request #1519 from felinira/wip/impl-trait-bounds
Add additional type bounds to Impl traits
2 parents d8dfa3a + 80569bd commit 5ec8462

26 files changed

+823
-262
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ Paolo Borelli:
258258
- gio: use `StrV` for the `file_info` API
259259
- gio: use `GStr` for the manual extension point implementation
260260
- glib: list: mark as transparent and impl TransparentPtr
261-
- glib: Rename `StrVItem` to `GStrPtr` and make it clonable and transparent
261+
- glib: Rename `StrVItem` to `GStrPtr` and make it cloneable and transparent
262262
- glib: `key_file`: return `PtrSlice<GStrPtr>`
263263
- glib-macros: further tweak docs
264264
- glib: Rename `GStrPtr` to `GStringPtr`

gdk-pixbuf/src/subclass/pixbuf_animation.rs

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*};
1313

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

16-
pub trait PixbufAnimationImpl: ObjectImpl {
16+
pub trait PixbufAnimationImpl: ObjectImpl
17+
where
18+
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
19+
<Self as ObjectSubclass>::Type: IsA<PixbufAnimation>,
20+
{
1721
fn is_static_image(&self) -> bool {
1822
self.parent_is_static_image()
1923
}
@@ -31,12 +35,11 @@ pub trait PixbufAnimationImpl: ObjectImpl {
3135
}
3236
}
3337

34-
mod sealed {
35-
pub trait Sealed {}
36-
impl<T: super::PixbufAnimationImplExt> Sealed for T {}
37-
}
38-
39-
pub trait PixbufAnimationImplExt: sealed::Sealed + ObjectSubclass {
38+
pub trait PixbufAnimationImplExt: ObjectSubclass + PixbufAnimationImpl
39+
where
40+
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
41+
<Self as ObjectSubclass>::Type: IsA<PixbufAnimation>,
42+
{
4043
fn parent_is_static_image(&self) -> bool {
4144
unsafe {
4245
let data = Self::type_data();
@@ -116,9 +119,18 @@ pub trait PixbufAnimationImplExt: sealed::Sealed + ObjectSubclass {
116119
}
117120
}
118121

119-
impl<T: PixbufAnimationImpl> PixbufAnimationImplExt for T {}
122+
impl<T: PixbufAnimationImpl> PixbufAnimationImplExt for T
123+
where
124+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
125+
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
126+
{
127+
}
120128

121-
unsafe impl<T: PixbufAnimationImpl> IsSubclassable<T> for PixbufAnimation {
129+
unsafe impl<T: PixbufAnimationImpl> IsSubclassable<T> for PixbufAnimation
130+
where
131+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
132+
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
133+
{
122134
fn class_init(class: &mut ::glib::Class<Self>) {
123135
Self::parent_class_init::<T>(class);
124136

@@ -132,7 +144,11 @@ unsafe impl<T: PixbufAnimationImpl> IsSubclassable<T> for PixbufAnimation {
132144

133145
unsafe extern "C" fn animation_is_static_image<T: PixbufAnimationImpl>(
134146
ptr: *mut ffi::GdkPixbufAnimation,
135-
) -> glib::ffi::gboolean {
147+
) -> glib::ffi::gboolean
148+
where
149+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
150+
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
151+
{
136152
let instance = &*(ptr as *mut T::Instance);
137153
let imp = instance.imp();
138154

@@ -143,7 +159,10 @@ unsafe extern "C" fn animation_get_size<T: PixbufAnimationImpl>(
143159
ptr: *mut ffi::GdkPixbufAnimation,
144160
width_ptr: *mut libc::c_int,
145161
height_ptr: *mut libc::c_int,
146-
) {
162+
) where
163+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
164+
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
165+
{
147166
if width_ptr.is_null() && height_ptr.is_null() {
148167
return;
149168
}
@@ -162,7 +181,11 @@ unsafe extern "C" fn animation_get_size<T: PixbufAnimationImpl>(
162181

163182
unsafe extern "C" fn animation_get_static_image<T: PixbufAnimationImpl>(
164183
ptr: *mut ffi::GdkPixbufAnimation,
165-
) -> *mut ffi::GdkPixbuf {
184+
) -> *mut ffi::GdkPixbuf
185+
where
186+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
187+
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
188+
{
166189
let instance = &*(ptr as *mut T::Instance);
167190
let imp = instance.imp();
168191

@@ -192,7 +215,11 @@ unsafe extern "C" fn animation_get_static_image<T: PixbufAnimationImpl>(
192215
unsafe extern "C" fn animation_get_iter<T: PixbufAnimationImpl>(
193216
ptr: *mut ffi::GdkPixbufAnimation,
194217
start_time_ptr: *const glib::ffi::GTimeVal,
195-
) -> *mut ffi::GdkPixbufAnimationIter {
218+
) -> *mut ffi::GdkPixbufAnimationIter
219+
where
220+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
221+
<T as ObjectSubclass>::Type: IsA<PixbufAnimation>,
222+
{
196223
let instance = &*(ptr as *mut T::Instance);
197224
let imp = instance.imp();
198225

gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*};
1212

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

15-
pub trait PixbufAnimationIterImpl: ObjectImpl {
15+
pub trait PixbufAnimationIterImpl: ObjectImpl
16+
where
17+
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
18+
<Self as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
19+
{
1620
// rustdoc-stripper-ignore-next
1721
/// Time in milliseconds, returning `None` implies showing the same pixbuf forever.
1822
fn delay_time(&self) -> Option<Duration> {
@@ -32,12 +36,11 @@ pub trait PixbufAnimationIterImpl: ObjectImpl {
3236
}
3337
}
3438

35-
mod sealed {
36-
pub trait Sealed {}
37-
impl<T: super::PixbufAnimationIterImplExt> Sealed for T {}
38-
}
39-
40-
pub trait PixbufAnimationIterImplExt: sealed::Sealed + ObjectSubclass {
39+
pub trait PixbufAnimationIterImplExt: ObjectSubclass + PixbufAnimationIterImpl
40+
where
41+
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
42+
<Self as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
43+
{
4144
fn parent_delay_time(&self) -> Option<Duration> {
4245
unsafe {
4346
let data = Self::type_data();
@@ -121,9 +124,18 @@ pub trait PixbufAnimationIterImplExt: sealed::Sealed + ObjectSubclass {
121124
}
122125
}
123126

124-
impl<T: PixbufAnimationIterImpl> PixbufAnimationIterImplExt for T {}
127+
impl<T: PixbufAnimationIterImpl> PixbufAnimationIterImplExt for T
128+
where
129+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
130+
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
131+
{
132+
}
125133

126-
unsafe impl<T: PixbufAnimationIterImpl> IsSubclassable<T> for PixbufAnimationIter {
134+
unsafe impl<T: PixbufAnimationIterImpl> IsSubclassable<T> for PixbufAnimationIter
135+
where
136+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
137+
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
138+
{
127139
fn class_init(class: &mut ::glib::Class<Self>) {
128140
Self::parent_class_init::<T>(class);
129141

@@ -137,7 +149,11 @@ unsafe impl<T: PixbufAnimationIterImpl> IsSubclassable<T> for PixbufAnimationIte
137149

138150
unsafe extern "C" fn animation_iter_get_delay_time<T: PixbufAnimationIterImpl>(
139151
ptr: *mut ffi::GdkPixbufAnimationIter,
140-
) -> i32 {
152+
) -> i32
153+
where
154+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
155+
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
156+
{
141157
let instance = &*(ptr as *mut T::Instance);
142158
let imp = instance.imp();
143159

@@ -146,7 +162,11 @@ unsafe extern "C" fn animation_iter_get_delay_time<T: PixbufAnimationIterImpl>(
146162

147163
unsafe extern "C" fn animation_iter_get_pixbuf<T: PixbufAnimationIterImpl>(
148164
ptr: *mut ffi::GdkPixbufAnimationIter,
149-
) -> *mut ffi::GdkPixbuf {
165+
) -> *mut ffi::GdkPixbuf
166+
where
167+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
168+
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
169+
{
150170
let instance = &*(ptr as *mut T::Instance);
151171
let imp = instance.imp();
152172

@@ -162,7 +182,11 @@ unsafe extern "C" fn animation_iter_get_pixbuf<T: PixbufAnimationIterImpl>(
162182

163183
unsafe extern "C" fn animation_iter_on_currently_loading_frame<T: PixbufAnimationIterImpl>(
164184
ptr: *mut ffi::GdkPixbufAnimationIter,
165-
) -> glib::ffi::gboolean {
185+
) -> glib::ffi::gboolean
186+
where
187+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
188+
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
189+
{
166190
let instance = &*(ptr as *mut T::Instance);
167191
let imp = instance.imp();
168192

@@ -172,7 +196,11 @@ unsafe extern "C" fn animation_iter_on_currently_loading_frame<T: PixbufAnimatio
172196
unsafe extern "C" fn animation_iter_advance<T: PixbufAnimationIterImpl>(
173197
ptr: *mut ffi::GdkPixbufAnimationIter,
174198
current_time_ptr: *const glib::ffi::GTimeVal,
175-
) -> glib::ffi::gboolean {
199+
) -> glib::ffi::gboolean
200+
where
201+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
202+
<T as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
203+
{
176204
let instance = &*(ptr as *mut T::Instance);
177205
let imp = instance.imp();
178206

gdk-pixbuf/src/subclass/pixbuf_loader.rs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*};
77

88
use crate::{ffi, PixbufLoader};
99

10-
pub trait PixbufLoaderImpl: ObjectImpl {
10+
pub trait PixbufLoaderImpl: ObjectImpl
11+
where
12+
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
13+
<Self as ObjectSubclass>::Type: IsA<PixbufLoader>,
14+
{
1115
fn size_prepared(&self, width: i32, height: i32) {
1216
self.parent_size_prepared(width, height)
1317
}
@@ -25,12 +29,11 @@ pub trait PixbufLoaderImpl: ObjectImpl {
2529
}
2630
}
2731

28-
mod sealed {
29-
pub trait Sealed {}
30-
impl<T: super::PixbufLoaderImplExt> Sealed for T {}
31-
}
32-
33-
pub trait PixbufLoaderImplExt: sealed::Sealed + ObjectSubclass {
32+
pub trait PixbufLoaderImplExt: ObjectSubclass + PixbufLoaderImpl
33+
where
34+
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
35+
<Self as ObjectSubclass>::Type: IsA<PixbufLoader>,
36+
{
3437
fn parent_size_prepared(&self, width: i32, height: i32) {
3538
unsafe {
3639
let data = Self::type_data();
@@ -96,9 +99,18 @@ pub trait PixbufLoaderImplExt: sealed::Sealed + ObjectSubclass {
9699
}
97100
}
98101

99-
impl<T: PixbufLoaderImpl> PixbufLoaderImplExt for T {}
102+
impl<T: PixbufLoaderImpl> PixbufLoaderImplExt for T
103+
where
104+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
105+
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
106+
{
107+
}
100108

101-
unsafe impl<T: PixbufLoaderImpl> IsSubclassable<T> for PixbufLoader {
109+
unsafe impl<T: PixbufLoaderImpl> IsSubclassable<T> for PixbufLoader
110+
where
111+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
112+
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
113+
{
102114
fn class_init(class: &mut ::glib::Class<Self>) {
103115
Self::parent_class_init::<T>(class);
104116

@@ -114,14 +126,21 @@ unsafe extern "C" fn loader_size_prepared<T: PixbufLoaderImpl>(
114126
ptr: *mut ffi::GdkPixbufLoader,
115127
width: i32,
116128
height: i32,
117-
) {
129+
) where
130+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
131+
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
132+
{
118133
let instance = &*(ptr as *mut T::Instance);
119134
let imp = instance.imp();
120135

121136
imp.size_prepared(width, height)
122137
}
123138

124-
unsafe extern "C" fn loader_area_prepared<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader) {
139+
unsafe extern "C" fn loader_area_prepared<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader)
140+
where
141+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
142+
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
143+
{
125144
let instance = &*(ptr as *mut T::Instance);
126145
let imp = instance.imp();
127146

@@ -134,14 +153,21 @@ unsafe extern "C" fn loader_area_updated<T: PixbufLoaderImpl>(
134153
y: i32,
135154
width: i32,
136155
height: i32,
137-
) {
156+
) where
157+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
158+
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
159+
{
138160
let instance = &*(ptr as *mut T::Instance);
139161
let imp = instance.imp();
140162

141163
imp.area_updated(x, y, width, height)
142164
}
143165

144-
unsafe extern "C" fn loader_closed<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader) {
166+
unsafe extern "C" fn loader_closed<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader)
167+
where
168+
<T as ObjectSubclass>::Type: IsA<glib::Object>,
169+
<T as ObjectSubclass>::Type: IsA<PixbufLoader>,
170+
{
145171
let instance = &*(ptr as *mut T::Instance);
146172
let imp = instance.imp();
147173

0 commit comments

Comments
 (0)