Skip to content

Commit 2a74d32

Browse files
make use of impl T wherever possible
Except in ClosureExpression because we can't mix both impl & generic types due to rust-lang/rust#83701
1 parent 7da69d5 commit 2a74d32

22 files changed

+126
-175
lines changed

gdk4/src/clipboard.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ use std::ptr;
1010

1111
impl Clipboard {
1212
#[doc(alias = "gdk_clipboard_read_async")]
13-
pub fn read_async<
14-
P: IsA<gio::Cancellable>,
15-
Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static,
16-
>(
13+
pub fn read_async<Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static>(
1714
&self,
1815
mime_types: &[&str],
1916
io_priority: glib::Priority,
20-
cancellable: Option<&P>,
17+
cancellable: Option<&impl IsA<gio::Cancellable>>,
2118
callback: Q,
2219
) {
2320
let user_data: Box<Q> = Box::new(callback);
@@ -89,10 +86,10 @@ impl Clipboard {
8986
}
9087

9188
#[doc(alias = "gdk_clipboard_store_async")]
92-
pub fn store_async<P: IsA<gio::Cancellable>, Q: FnOnce(Result<(), glib::Error>) + 'static>(
89+
pub fn store_async<Q: FnOnce(Result<(), glib::Error>) + 'static>(
9390
&self,
9491
io_priority: glib::Priority,
95-
cancellable: Option<&P>,
92+
cancellable: Option<&impl IsA<gio::Cancellable>>,
9693
callback: Q,
9794
) {
9895
let user_data: Box<Q> = Box::new(callback);
@@ -137,14 +134,11 @@ impl Clipboard {
137134
}
138135

139136
#[doc(alias = "gdk_clipboard_read_value_async")]
140-
pub fn read_value_async<
141-
P: IsA<gio::Cancellable>,
142-
Q: FnOnce(Result<glib::Value, glib::Error>) + 'static,
143-
>(
137+
pub fn read_value_async<Q: FnOnce(Result<glib::Value, glib::Error>) + 'static>(
144138
&self,
145139
type_: glib::types::Type,
146140
io_priority: glib::Priority,
147-
cancellable: Option<&P>,
141+
cancellable: Option<&impl IsA<gio::Cancellable>>,
148142
callback: Q,
149143
) {
150144
let user_data: Box<Q> = Box::new(callback);
@@ -193,12 +187,9 @@ impl Clipboard {
193187
}
194188

195189
#[doc(alias = "gdk_clipboard_read_text_async")]
196-
pub fn read_text_async<
197-
P: IsA<gio::Cancellable>,
198-
Q: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static,
199-
>(
190+
pub fn read_text_async<Q: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static>(
200191
&self,
201-
cancellable: Option<&P>,
192+
cancellable: Option<&impl IsA<gio::Cancellable>>,
202193
callback: Q,
203194
) {
204195
let user_data: Box<Q> = Box::new(callback);
@@ -244,12 +235,9 @@ impl Clipboard {
244235
}
245236

246237
#[doc(alias = "gdk_clipboard_read_texture_async")]
247-
pub fn read_texture_async<
248-
P: IsA<gio::Cancellable>,
249-
Q: FnOnce(Result<Option<Texture>, glib::Error>) + 'static,
250-
>(
238+
pub fn read_texture_async<Q: FnOnce(Result<Option<Texture>, glib::Error>) + 'static>(
251239
&self,
252-
cancellable: Option<&P>,
240+
cancellable: Option<&impl IsA<gio::Cancellable>>,
253241
callback: Q,
254242
) {
255243
let user_data: Box<Q> = Box::new(callback);

gdk4/src/drop.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ use std::ptr;
1111

1212
impl Drop {
1313
#[doc(alias = "gdk_drop_read_async")]
14-
pub fn read_async<
15-
P: IsA<gio::Cancellable>,
16-
Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static,
17-
>(
14+
pub fn read_async<Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static>(
1815
&self,
1916
mime_types: &[&str],
2017
io_priority: glib::Priority,
21-
cancellable: Option<&P>,
18+
cancellable: Option<&impl IsA<gio::Cancellable>>,
2219
callback: Q,
2320
) {
2421
let user_data: Box<Q> = Box::new(callback);
@@ -81,14 +78,11 @@ impl Drop {
8178
}
8279

8380
#[doc(alias = "gdk_drop_read_value_async")]
84-
pub fn read_value_async<
85-
P: IsA<gio::Cancellable>,
86-
Q: FnOnce(Result<glib::Value, glib::Error>) + 'static,
87-
>(
81+
pub fn read_value_async<Q: FnOnce(Result<glib::Value, glib::Error>) + 'static>(
8882
&self,
8983
type_: glib::types::Type,
9084
io_priority: glib::Priority,
91-
cancellable: Option<&P>,
85+
cancellable: Option<&impl IsA<gio::Cancellable>>,
9286
callback: Q,
9387
) {
9488
let user_data: Box<Q> = Box::new(callback);

gdk4/src/event.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Event {
2929

3030
#[doc(alias = "gdk_events_get_angle")]
3131
#[doc(alias = "get_angle")]
32-
pub fn angle<P: AsRef<Event>>(&self, event: P) -> Option<f64> {
32+
pub fn angle(&self, event: impl AsRef<Event>) -> Option<f64> {
3333
skip_assert_initialized!();
3434
unsafe {
3535
let mut angle = mem::MaybeUninit::uninit();
@@ -49,7 +49,7 @@ impl Event {
4949

5050
#[doc(alias = "gdk_events_get_center")]
5151
#[doc(alias = "get_center")]
52-
pub fn center<P: AsRef<Event>>(&self, event: P) -> Option<(f64, f64)> {
52+
pub fn center(&self, event: impl AsRef<Event>) -> Option<(f64, f64)> {
5353
skip_assert_initialized!();
5454
unsafe {
5555
let mut x = mem::MaybeUninit::uninit();
@@ -72,7 +72,7 @@ impl Event {
7272

7373
#[doc(alias = "gdk_events_get_distance")]
7474
#[doc(alias = "get_distance")]
75-
pub fn distance<P: AsRef<Event>>(&self, event: P) -> Option<f64> {
75+
pub fn distance(&self, event: impl AsRef<Event>) -> Option<f64> {
7676
skip_assert_initialized!();
7777
unsafe {
7878
let mut distance = mem::MaybeUninit::uninit();

gdk4/src/functions.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ pub fn pango_layout_get_clip_region(
3232
}
3333

3434
#[doc(alias = "gdk_content_deserialize_async")]
35-
pub fn content_deserialize_async<
36-
P: IsA<gio::InputStream>,
37-
Q: IsA<gio::Cancellable>,
38-
R: FnOnce(Result<glib::Value, glib::Error>) + Send + 'static,
39-
>(
40-
stream: &P,
35+
pub fn content_deserialize_async<R: FnOnce(Result<glib::Value, glib::Error>) + Send + 'static>(
36+
stream: &impl IsA<gio::InputStream>,
4137
mime_type: &str,
4238
type_: glib::types::Type,
4339
io_priority: glib::Priority,
44-
cancellable: Option<&Q>,
40+
cancellable: Option<&impl IsA<gio::Cancellable>>,
4541
callback: R,
4642
) {
4743
assert_initialized_main_thread!();
@@ -78,8 +74,8 @@ pub fn content_deserialize_async<
7874
}
7975
}
8076

81-
pub fn content_deserialize_future<P: IsA<gio::InputStream> + Clone + 'static>(
82-
stream: &P,
77+
pub fn content_deserialize_future(
78+
stream: &(impl IsA<gio::InputStream> + Clone + 'static),
8379
mime_type: &str,
8480
type_: glib::types::Type,
8581
io_priority: glib::Priority,
@@ -222,16 +218,12 @@ pub fn content_register_serializer<
222218
}
223219

224220
#[doc(alias = "gdk_content_serialize_async")]
225-
pub fn content_serialize_async<
226-
P: IsA<gio::OutputStream>,
227-
Q: IsA<gio::Cancellable>,
228-
R: FnOnce(Result<(), glib::Error>) + Send + 'static,
229-
>(
230-
stream: &P,
221+
pub fn content_serialize_async<R: FnOnce(Result<(), glib::Error>) + Send + 'static>(
222+
stream: &impl IsA<gio::OutputStream>,
231223
mime_type: &str,
232224
value: &glib::Value,
233225
io_priority: glib::Priority,
234-
cancellable: Option<&Q>,
226+
cancellable: Option<&impl IsA<gio::Cancellable>>,
235227
callback: R,
236228
) {
237229
assert_initialized_main_thread!();
@@ -267,8 +259,8 @@ pub fn content_serialize_async<
267259
}
268260
}
269261

270-
pub fn content_serialize_future<P: IsA<gio::OutputStream> + Clone + 'static>(
271-
stream: &P,
262+
pub fn content_serialize_future(
263+
stream: &(impl IsA<gio::OutputStream> + Clone + 'static),
272264
mime_type: &str,
273265
value: &glib::Value,
274266
io_priority: glib::Priority,

gtk4/src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::Path;
99
impl Builder {
1010
#[doc(alias = "gtk_builder_new_from_file")]
1111
#[doc(alias = "new_from_file")]
12-
pub fn from_file<T: AsRef<Path>>(file_path: T) -> Self {
12+
pub fn from_file(file_path: impl AsRef<Path>) -> Self {
1313
assert_initialized_main_thread!();
1414
unsafe {
1515
from_glib_full(ffi::gtk_builder_new_from_file(
@@ -45,7 +45,7 @@ impl Builder {
4545
}
4646

4747
#[doc(alias = "gtk_builder_add_from_file")]
48-
pub fn add_from_file<T: AsRef<Path>>(&self, file_path: T) -> Result<(), glib::Error> {
48+
pub fn add_from_file(&self, file_path: impl AsRef<Path>) -> Result<(), glib::Error> {
4949
unsafe {
5050
let mut error = ::std::ptr::null_mut();
5151
ffi::gtk_builder_add_from_file(

gtk4/src/cell_area.rs

+27-35
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,43 @@ pub trait CellAreaExtManual {
1717
);
1818

1919
#[doc(alias = "gtk_cell_area_activate_cell")]
20-
fn activate_cell<P: IsA<Widget>, Q: IsA<CellRenderer>, R: AsRef<Event>>(
20+
fn activate_cell(
2121
&self,
22-
widget: &P,
23-
renderer: &Q,
24-
event: &R,
22+
widget: &impl IsA<Widget>,
23+
renderer: &impl IsA<CellRenderer>,
24+
event: &impl AsRef<Event>,
2525
cell_area: &gdk::Rectangle,
2626
flags: CellRendererState,
2727
) -> bool;
2828

2929
#[doc(alias = "gtk_cell_area_event")]
30-
fn event<P: IsA<CellAreaContext>, Q: IsA<Widget>, R: AsRef<Event>>(
30+
fn event(
3131
&self,
32-
context: &P,
33-
widget: &Q,
34-
event: &R,
32+
context: &impl IsA<CellAreaContext>,
33+
widget: &impl IsA<Widget>,
34+
event: &impl AsRef<Event>,
3535
cell_area: &gdk::Rectangle,
3636
flags: CellRendererState,
3737
) -> i32;
3838

3939
#[doc(alias = "gtk_cell_area_cell_get_valist")]
4040
#[doc(alias = "gtk_cell_area_cell_get_property")]
41-
fn cell_get_value<P: IsA<CellRenderer>>(
42-
&self,
43-
renderer: &P,
44-
property_name: &str,
45-
) -> glib::Value;
41+
fn cell_get_value(&self, renderer: &impl IsA<CellRenderer>, property_name: &str)
42+
-> glib::Value;
4643

4744
// rustdoc-stripper-ignore-next
4845
/// Similar to [`Self::cell_get_value`] but panics if the value is of a different type.
4946
#[doc(alias = "gtk_cell_area_cell_get_valist")]
5047
#[doc(alias = "gtk_cell_area_cell_get_property")]
51-
fn cell_get<V: for<'b> FromValue<'b> + 'static, P: IsA<CellRenderer>>(
48+
fn cell_get<V: for<'b> FromValue<'b> + 'static>(
5249
&self,
53-
renderer: &P,
50+
renderer: &impl IsA<CellRenderer>,
5451
property_name: &str,
5552
) -> V;
5653

5754
#[doc(alias = "gtk_cell_area_cell_set_valist")]
5855
#[doc(alias = "gtk_cell_area_cell_set_property")]
59-
fn cell_set<P: IsA<CellRenderer>>(
60-
&self,
61-
renderer: &P,
62-
property_name: &str,
63-
value: &dyn ToValue,
64-
);
56+
fn cell_set(&self, renderer: &impl IsA<CellRenderer>, property_name: &str, value: &dyn ToValue);
6557
}
6658

6759
impl<O: IsA<CellArea>> CellAreaExtManual for O {
@@ -75,11 +67,11 @@ impl<O: IsA<CellArea>> CellAreaExtManual for O {
7567
self.as_ref().cell_set(renderer, property_name, *value);
7668
});
7769
}
78-
fn activate_cell<P: IsA<Widget>, Q: IsA<CellRenderer>, R: AsRef<Event>>(
70+
fn activate_cell(
7971
&self,
80-
widget: &P,
81-
renderer: &Q,
82-
event: &R,
72+
widget: &impl IsA<Widget>,
73+
renderer: &impl IsA<CellRenderer>,
74+
event: &impl AsRef<Event>,
8375
cell_area: &gdk::Rectangle,
8476
flags: CellRendererState,
8577
) -> bool {
@@ -95,9 +87,9 @@ impl<O: IsA<CellArea>> CellAreaExtManual for O {
9587
}
9688
}
9789

98-
fn cell_get_value<P: IsA<CellRenderer>>(
90+
fn cell_get_value(
9991
&self,
100-
renderer: &P,
92+
renderer: &impl IsA<CellRenderer>,
10193
property_name: &str,
10294
) -> glib::Value {
10395
unsafe {
@@ -121,9 +113,9 @@ impl<O: IsA<CellArea>> CellAreaExtManual for O {
121113
}
122114
}
123115

124-
fn cell_get<V: for<'b> FromValue<'b> + 'static, P: IsA<CellRenderer>>(
116+
fn cell_get<V: for<'b> FromValue<'b> + 'static>(
125117
&self,
126-
renderer: &P,
118+
renderer: &impl IsA<CellRenderer>,
127119
property_name: &str,
128120
) -> V {
129121
let value = self.cell_get_value(renderer, property_name);
@@ -132,9 +124,9 @@ impl<O: IsA<CellArea>> CellAreaExtManual for O {
132124
.expect("Failed to get value of renderer")
133125
}
134126

135-
fn cell_set<P: IsA<CellRenderer>>(
127+
fn cell_set(
136128
&self,
137-
renderer: &P,
129+
renderer: &impl IsA<CellRenderer>,
138130
property_name: &str,
139131
value: &dyn ToValue,
140132
) {
@@ -165,11 +157,11 @@ impl<O: IsA<CellArea>> CellAreaExtManual for O {
165157
}
166158
}
167159

168-
fn event<P: IsA<CellAreaContext>, Q: IsA<Widget>, R: AsRef<Event>>(
160+
fn event(
169161
&self,
170-
context: &P,
171-
widget: &Q,
172-
event: &R,
162+
context: &impl IsA<CellAreaContext>,
163+
widget: &impl IsA<Widget>,
164+
event: &impl AsRef<Event>,
173165
cell_area: &gdk::Rectangle,
174166
flags: CellRendererState,
175167
) -> i32 {

gtk4/src/cell_editable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use glib::IsA;
66

77
pub trait CellEditableExtManual {
88
#[doc(alias = "gtk_cell_editable_start_editing")]
9-
fn start_editing<P: AsRef<gdk::Event>>(&self, event: Option<&P>);
9+
fn start_editing(&self, event: Option<&impl AsRef<gdk::Event>>);
1010
}
1111

1212
impl<O: IsA<CellEditable>> CellEditableExtManual for O {
13-
fn start_editing<P: AsRef<gdk::Event>>(&self, event: Option<&P>) {
13+
fn start_editing(&self, event: Option<&impl AsRef<gdk::Event>>) {
1414
unsafe {
1515
ffi::gtk_cell_editable_start_editing(
1616
self.as_ref().to_glib_none().0,

0 commit comments

Comments
 (0)