Skip to content

Commit 55210d5

Browse files
Generate trait signature once for manual code
1 parent 3c0e253 commit 55210d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+357
-1225
lines changed

gio/src/action_map.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@ use glib::{clone, prelude::*};
44

55
use crate::{prelude::*, ActionEntry, ActionMap, SimpleAction};
66

7-
pub trait ActionMapExtManual {
7+
pub trait ActionMapExtManual: IsA<ActionMap> {
88
#[doc(alias = "g_action_map_add_action_entries")]
9-
fn add_action_entries(&self, entries: impl IntoIterator<Item = ActionEntry<Self>>)
10-
where
11-
Self: IsA<ActionMap>;
12-
}
13-
14-
impl<O: IsA<ActionMap>> ActionMapExtManual for O {
159
fn add_action_entries(&self, entries: impl IntoIterator<Item = ActionEntry<Self>>) {
1610
for entry in entries.into_iter() {
1711
let action = if let Some(state) = entry.state() {
@@ -23,16 +17,18 @@ impl<O: IsA<ActionMap>> ActionMapExtManual for O {
2317
if let Some(callback) = entry.activate {
2418
action.connect_activate(clone!(@strong action_map => move |action, state| {
2519
// safe to unwrap as O: IsA<ActionMap>
26-
callback(action_map.downcast_ref::<O>().unwrap(), action, state);
20+
callback(action_map.downcast_ref::<Self>().unwrap(), action, state);
2721
}));
2822
}
2923
if let Some(callback) = entry.change_state {
3024
action.connect_change_state(clone!(@strong action_map => move |action, state| {
3125
// safe to unwrap as O: IsA<ActionMap>
32-
callback(action_map.downcast_ref::<O>().unwrap(), action, state);
26+
callback(action_map.downcast_ref::<Self>().unwrap(), action, state);
3327
}));
3428
}
3529
self.as_ref().add_action(&action);
3630
}
3731
}
3832
}
33+
34+
impl<O: IsA<ActionMap>> ActionMapExtManual for O {}

gio/src/app_info.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,10 @@ use crate::AppLaunchContext;
1717
#[cfg(feature = "v2_60")]
1818
use crate::Cancellable;
1919

20-
pub trait AppInfoExtManual: 'static {
20+
pub trait AppInfoExtManual: IsA<AppInfo> + 'static {
2121
#[cfg(feature = "v2_60")]
2222
#[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
2323
#[doc(alias = "g_app_info_launch_uris_async")]
24-
fn launch_uris_async<
25-
P: IsA<AppLaunchContext>,
26-
Q: IsA<Cancellable>,
27-
R: FnOnce(Result<(), glib::Error>) + 'static,
28-
>(
29-
&self,
30-
uris: &[&str],
31-
context: Option<&P>,
32-
cancellable: Option<&Q>,
33-
callback: R,
34-
);
35-
36-
#[cfg(feature = "v2_60")]
37-
#[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
38-
fn launch_uris_future<P: IsA<AppLaunchContext> + Clone + 'static>(
39-
&self,
40-
uris: &[&str],
41-
context: Option<&P>,
42-
) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>;
43-
}
44-
45-
impl<O: IsA<AppInfo>> AppInfoExtManual for O {
46-
#[cfg(feature = "v2_60")]
47-
#[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
4824
fn launch_uris_async<
4925
P: IsA<AppLaunchContext>,
5026
Q: IsA<Cancellable>,
@@ -133,3 +109,5 @@ impl<O: IsA<AppInfo>> AppInfoExtManual for O {
133109
))
134110
}
135111
}
112+
113+
impl<O: IsA<AppInfo>> AppInfoExtManual for O {}

gio/src/application.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,12 @@ use glib::{
1111

1212
use crate::{Application, File};
1313

14-
pub trait ApplicationExtManual {
14+
pub trait ApplicationExtManual: IsA<Application> {
1515
#[doc(alias = "g_application_run")]
16-
fn run(&self) -> ExitCode;
17-
#[doc(alias = "g_application_run")]
18-
fn run_with_args<S: AsRef<str>>(&self, args: &[S]) -> ExitCode;
19-
fn connect_open<F: Fn(&Self, &[File], &str) + 'static>(&self, f: F) -> SignalHandlerId;
20-
21-
#[doc(alias = "g_application_hold")]
22-
fn hold(&self) -> ApplicationHoldGuard;
23-
24-
#[doc(alias = "g_application_mark_busy")]
25-
fn mark_busy(&self) -> ApplicationBusyGuard;
26-
}
27-
28-
impl<O: IsA<Application>> ApplicationExtManual for O {
2916
fn run(&self) -> ExitCode {
3017
self.run_with_args(&std::env::args().collect::<Vec<_>>())
3118
}
32-
19+
#[doc(alias = "g_application_run")]
3320
fn run_with_args<S: AsRef<str>>(&self, args: &[S]) -> ExitCode {
3421
let argv: Vec<&str> = args.iter().map(|a| a.as_ref()).collect();
3522
let argc = argv.len() as i32;
@@ -38,7 +25,6 @@ impl<O: IsA<Application>> ApplicationExtManual for O {
3825
};
3926
ExitCode::from(exit_code)
4027
}
41-
4228
fn connect_open<F: Fn(&Self, &[File], &str) + 'static>(&self, f: F) -> SignalHandlerId {
4329
unsafe extern "C" fn open_trampoline<P, F: Fn(&P, &[File], &str) + 'static>(
4430
this: *mut ffi::GApplication,
@@ -70,13 +56,15 @@ impl<O: IsA<Application>> ApplicationExtManual for O {
7056
}
7157
}
7258

59+
#[doc(alias = "g_application_hold")]
7360
fn hold(&self) -> ApplicationHoldGuard {
7461
unsafe {
7562
ffi::g_application_hold(self.as_ref().to_glib_none().0);
7663
}
7764
ApplicationHoldGuard(self.as_ref().downgrade())
7865
}
7966

67+
#[doc(alias = "g_application_mark_busy")]
8068
fn mark_busy(&self) -> ApplicationBusyGuard {
8169
unsafe {
8270
ffi::g_application_mark_busy(self.as_ref().to_glib_none().0);
@@ -85,6 +73,8 @@ impl<O: IsA<Application>> ApplicationExtManual for O {
8573
}
8674
}
8775

76+
impl<O: IsA<Application>> ApplicationExtManual for O {}
77+
8878
#[derive(Debug)]
8979
#[must_use = "if unused the Application will immediately be released"]
9080
pub struct ApplicationHoldGuard(glib::WeakRef<Application>);

gio/src/cancellable.rs

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl TryFromGlib<libc::c_ulong> for CancelledHandlerId {
3232
}
3333
}
3434

35-
pub trait CancellableExtManual {
35+
pub trait CancellableExtManual: IsA<Cancellable> {
3636
// rustdoc-stripper-ignore-next
3737
/// Convenience function to connect to the `signal::Cancellable::cancelled` signal. Also
3838
/// handles the race condition that may happen if the cancellable is cancelled right before
@@ -51,39 +51,6 @@ pub trait CancellableExtManual {
5151
/// # Returns
5252
///
5353
/// The id of the signal handler or `None` if `self` has already been cancelled.
54-
#[doc(alias = "g_cancellable_connect")]
55-
fn connect_cancelled<F: FnOnce(&Self) + Send + 'static>(
56-
&self,
57-
callback: F,
58-
) -> Option<CancelledHandlerId>;
59-
// rustdoc-stripper-ignore-next
60-
/// Local variant of [`Self::connect_cancelled`].
61-
#[doc(alias = "g_cancellable_connect")]
62-
fn connect_cancelled_local<F: FnOnce(&Self) + 'static>(
63-
&self,
64-
callback: F,
65-
) -> Option<CancelledHandlerId>;
66-
// rustdoc-stripper-ignore-next
67-
/// Disconnects a handler from a cancellable instance. Additionally, in the event that a signal
68-
/// handler is currently running, this call will block until the handler has finished. Calling
69-
/// this function from a callback registered with [`Self::connect_cancelled`] will therefore
70-
/// result in a deadlock.
71-
///
72-
/// This avoids a race condition where a thread cancels at the same time as the cancellable
73-
/// operation is finished and the signal handler is removed.
74-
#[doc(alias = "g_cancellable_disconnect")]
75-
fn disconnect_cancelled(&self, id: CancelledHandlerId);
76-
// rustdoc-stripper-ignore-next
77-
/// Returns a `Future` that completes when the cancellable becomes cancelled. Completes
78-
/// immediately if the cancellable is already cancelled.
79-
fn future(&self) -> std::pin::Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>>;
80-
// rustdoc-stripper-ignore-next
81-
/// Set an error if the cancellable is already cancelled.
82-
#[doc(alias = "g_cancellable_set_error_if_cancelled")]
83-
fn set_error_if_cancelled(&self) -> Result<(), glib::Error>;
84-
}
85-
86-
impl<O: IsA<Cancellable>> CancellableExtManual for O {
8754
#[doc(alias = "g_cancellable_connect")]
8855
fn connect_cancelled<F: FnOnce(&Self) + Send + 'static>(
8956
&self,
@@ -116,6 +83,8 @@ impl<O: IsA<Cancellable>> CancellableExtManual for O {
11683
))
11784
}
11885
}
86+
// rustdoc-stripper-ignore-next
87+
/// Local variant of [`Self::connect_cancelled`].
11988
#[doc(alias = "g_cancellable_connect")]
12089
fn connect_cancelled_local<F: FnOnce(&Self) + 'static>(
12190
&self,
@@ -125,10 +94,21 @@ impl<O: IsA<Cancellable>> CancellableExtManual for O {
12594

12695
self.connect_cancelled(move |obj| (callback.into_inner())(obj))
12796
}
97+
// rustdoc-stripper-ignore-next
98+
/// Disconnects a handler from a cancellable instance. Additionally, in the event that a signal
99+
/// handler is currently running, this call will block until the handler has finished. Calling
100+
/// this function from a callback registered with [`Self::connect_cancelled`] will therefore
101+
/// result in a deadlock.
102+
///
103+
/// This avoids a race condition where a thread cancels at the same time as the cancellable
104+
/// operation is finished and the signal handler is removed.
128105
#[doc(alias = "g_cancellable_disconnect")]
129106
fn disconnect_cancelled(&self, id: CancelledHandlerId) {
130107
unsafe { ffi::g_cancellable_disconnect(self.as_ptr() as *mut _, id.as_raw()) };
131108
}
109+
// rustdoc-stripper-ignore-next
110+
/// Returns a `Future` that completes when the cancellable becomes cancelled. Completes
111+
/// immediately if the cancellable is already cancelled.
132112
fn future(&self) -> std::pin::Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>> {
133113
let cancellable = self.as_ref().clone();
134114
let (tx, rx) = oneshot::channel();
@@ -142,7 +122,9 @@ impl<O: IsA<Cancellable>> CancellableExtManual for O {
142122
}
143123
})
144124
}
145-
125+
// rustdoc-stripper-ignore-next
126+
/// Set an error if the cancellable is already cancelled.
127+
#[doc(alias = "g_cancellable_set_error_if_cancelled")]
146128
fn set_error_if_cancelled(&self) -> Result<(), glib::Error> {
147129
unsafe {
148130
let mut error = std::ptr::null_mut();
@@ -162,6 +144,8 @@ impl<O: IsA<Cancellable>> CancellableExtManual for O {
162144
}
163145
}
164146

147+
impl<O: IsA<Cancellable>> CancellableExtManual for O {}
148+
165149
#[cfg(test)]
166150
mod tests {
167151
use super::*;

gio/src/converter.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,7 @@ use glib::{prelude::*, translate::*};
66

77
use crate::{Converter, ConverterFlags, ConverterResult};
88

9-
pub trait ConverterExtManual {
10-
#[doc(alias = "g_converter_convert")]
11-
fn convert<IN: AsRef<[u8]>, OUT: AsMut<[u8]>>(
12-
&self,
13-
inbuf: IN,
14-
outbuf: OUT,
15-
flags: ConverterFlags,
16-
) -> Result<(ConverterResult, usize, usize), glib::Error>;
17-
}
18-
19-
impl<O: IsA<Converter>> ConverterExtManual for O {
9+
pub trait ConverterExtManual: IsA<Converter> + 'static {
2010
#[doc(alias = "g_converter_convert")]
2111
fn convert<IN: AsRef<[u8]>, OUT: AsMut<[u8]>>(
2212
&self,
@@ -61,3 +51,5 @@ impl<O: IsA<Converter>> ConverterExtManual for O {
6151
}
6252
}
6353
}
54+
55+
impl<O: IsA<Converter>> ConverterExtManual for O {}

gio/src/data_input_stream.rs

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,71 +6,8 @@ use glib::{prelude::*, translate::*, GString};
66

77
use crate::{Cancellable, DataInputStream};
88

9-
pub trait DataInputStreamExtManual: 'static {
9+
pub trait DataInputStreamExtManual: IsA<DataInputStream> + 'static {
1010
#[doc(alias = "g_data_input_stream_read_line")]
11-
fn read_line<P: IsA<Cancellable>>(
12-
&self,
13-
cancellable: Option<&P>,
14-
) -> Result<Vec<u8>, glib::Error>;
15-
16-
#[doc(alias = "g_data_input_stream_read_line_async")]
17-
fn read_line_async<P: IsA<Cancellable>, Q: FnOnce(Result<Vec<u8>, glib::Error>) + 'static>(
18-
&self,
19-
io_priority: glib::Priority,
20-
cancellable: Option<&P>,
21-
callback: Q,
22-
);
23-
24-
fn read_line_future(
25-
&self,
26-
io_priority: glib::Priority,
27-
) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<u8>, glib::Error>> + 'static>>;
28-
29-
#[doc(alias = "g_data_input_stream_read_line_utf8")]
30-
fn read_line_utf8<P: IsA<Cancellable>>(
31-
&self,
32-
cancellable: Option<&P>,
33-
) -> Result<Option<GString>, glib::Error>;
34-
35-
fn read_line_utf8_async<
36-
P: IsA<Cancellable>,
37-
Q: FnOnce(Result<Option<GString>, glib::Error>) + 'static,
38-
>(
39-
&self,
40-
io_priority: glib::Priority,
41-
cancellable: Option<&P>,
42-
callback: Q,
43-
);
44-
45-
fn read_line_utf8_future(
46-
&self,
47-
io_priority: glib::Priority,
48-
) -> Pin<Box_<dyn std::future::Future<Output = Result<Option<GString>, glib::Error>> + 'static>>;
49-
50-
#[doc(alias = "g_data_input_stream_read_upto")]
51-
fn read_upto<P: IsA<Cancellable>>(
52-
&self,
53-
stop_chars: &[u8],
54-
cancellable: Option<&P>,
55-
) -> Result<Vec<u8>, glib::Error>;
56-
57-
#[doc(alias = "g_data_input_stream_read_upto_async")]
58-
fn read_upto_async<P: IsA<Cancellable>, Q: FnOnce(Result<Vec<u8>, glib::Error>) + 'static>(
59-
&self,
60-
stop_chars: &[u8],
61-
io_priority: glib::Priority,
62-
cancellable: Option<&P>,
63-
callback: Q,
64-
);
65-
66-
fn read_upto_future(
67-
&self,
68-
stop_chars: &[u8],
69-
io_priority: glib::Priority,
70-
) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<u8>, glib::Error>> + 'static>>;
71-
}
72-
73-
impl<O: IsA<DataInputStream>> DataInputStreamExtManual for O {
7411
fn read_line<P: IsA<Cancellable>>(
7512
&self,
7613
cancellable: Option<&P>,
@@ -93,6 +30,7 @@ impl<O: IsA<DataInputStream>> DataInputStreamExtManual for O {
9330
}
9431
}
9532

33+
#[doc(alias = "g_data_input_stream_read_line_async")]
9634
fn read_line_async<P: IsA<Cancellable>, Q: FnOnce(Result<Vec<u8>, glib::Error>) + 'static>(
9735
&self,
9836
io_priority: glib::Priority,
@@ -163,6 +101,7 @@ impl<O: IsA<DataInputStream>> DataInputStreamExtManual for O {
163101
))
164102
}
165103

104+
#[doc(alias = "g_data_input_stream_read_line_utf8")]
166105
fn read_line_utf8<P: IsA<Cancellable>>(
167106
&self,
168107
cancellable: Option<&P>,
@@ -255,6 +194,7 @@ impl<O: IsA<DataInputStream>> DataInputStreamExtManual for O {
255194
))
256195
}
257196

197+
#[doc(alias = "g_data_input_stream_read_upto")]
258198
fn read_upto<P: IsA<Cancellable>>(
259199
&self,
260200
stop_chars: &[u8],
@@ -284,6 +224,7 @@ impl<O: IsA<DataInputStream>> DataInputStreamExtManual for O {
284224
}
285225
}
286226

227+
#[doc(alias = "g_data_input_stream_read_upto_async")]
287228
fn read_upto_async<P: IsA<Cancellable>, Q: FnOnce(Result<Vec<u8>, glib::Error>) + 'static>(
288229
&self,
289230
stop_chars: &[u8],
@@ -363,3 +304,5 @@ impl<O: IsA<DataInputStream>> DataInputStreamExtManual for O {
363304
))
364305
}
365306
}
307+
308+
impl<O: IsA<DataInputStream>> DataInputStreamExtManual for O {}

0 commit comments

Comments
 (0)