Skip to content

Commit b67ac89

Browse files
committed
glib/gio: Replace various type parameters with impl trait
1 parent 5dbd381 commit b67ac89

File tree

11 files changed

+29
-33
lines changed

11 files changed

+29
-33
lines changed

gio/src/socket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket}
2424

2525
impl Socket {
2626
#[cfg(any(unix, feature = "dox"))]
27-
pub unsafe fn from_fd<T: IntoRawFd>(fd: T) -> Result<Socket, glib::Error> {
27+
pub unsafe fn from_fd(fd: impl IntoRawFd) -> Result<Socket, glib::Error> {
2828
let fd = fd.into_raw_fd();
2929
let mut error = ptr::null_mut();
3030
let ret = ffi::g_socket_new_from_fd(fd, &mut error);
@@ -35,7 +35,7 @@ impl Socket {
3535
}
3636
}
3737
#[cfg(any(windows, feature = "dox"))]
38-
pub unsafe fn from_socket<T: IntoRawSocket>(socket: T) -> Result<Socket, glib::Error> {
38+
pub unsafe fn from_socket(socket: impl IntoRawSocket) -> Result<Socket, glib::Error> {
3939
let socket = socket.into_raw_socket();
4040
let mut error = ptr::null_mut();
4141
let ret = ffi::g_socket_new_from_fd(socket as i32, &mut error);

gio/src/subprocess_launcher.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl SubprocessLauncher {
1818
#[cfg(any(unix, feature = "dox"))]
1919
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
2020
#[doc(alias = "g_subprocess_launcher_take_fd")]
21-
pub fn take_fd<F: IntoRawFd, G: IntoRawFd>(&self, source_fd: F, target_fd: G) {
21+
pub fn take_fd(&self, source_fd: impl IntoRawFd, target_fd: impl IntoRawFd) {
2222
unsafe {
2323
ffi::g_subprocess_launcher_take_fd(
2424
self.to_glib_none().0,
@@ -31,7 +31,7 @@ impl SubprocessLauncher {
3131
#[cfg(any(unix, feature = "dox"))]
3232
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
3333
#[doc(alias = "g_subprocess_launcher_take_stderr_fd")]
34-
pub fn take_stderr_fd<F: IntoRawFd>(&self, fd: F) {
34+
pub fn take_stderr_fd(&self, fd: impl IntoRawFd) {
3535
unsafe {
3636
ffi::g_subprocess_launcher_take_stderr_fd(self.to_glib_none().0, fd.into_raw_fd());
3737
}
@@ -40,7 +40,7 @@ impl SubprocessLauncher {
4040
#[cfg(any(unix, feature = "dox"))]
4141
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
4242
#[doc(alias = "g_subprocess_launcher_take_stdin_fd")]
43-
pub fn take_stdin_fd<F: IntoRawFd>(&self, fd: F) {
43+
pub fn take_stdin_fd(&self, fd: impl IntoRawFd) {
4444
unsafe {
4545
ffi::g_subprocess_launcher_take_stdin_fd(self.to_glib_none().0, fd.into_raw_fd());
4646
}
@@ -49,7 +49,7 @@ impl SubprocessLauncher {
4949
#[cfg(any(unix, feature = "dox"))]
5050
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
5151
#[doc(alias = "g_subprocess_launcher_take_stdout_fd")]
52-
pub fn take_stdout_fd<F: IntoRawFd>(&self, fd: F) {
52+
pub fn take_stdout_fd(&self, fd: impl IntoRawFd) {
5353
unsafe {
5454
ffi::g_subprocess_launcher_take_stdout_fd(self.to_glib_none().0, fd.into_raw_fd());
5555
}

gio/src/unix_fd_list.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ use socket::{AsRawFd, IntoRawFd, RawFd};
1313

1414
impl UnixFDList {
1515
#[doc(alias = "g_unix_fd_list_new_from_array")]
16-
pub fn from_array<T>(fds: T) -> UnixFDList
17-
where
18-
T: IntoIterator,
19-
T::Item: IntoRawFd,
20-
{
16+
pub fn from_array(fds: impl IntoIterator<Item = impl IntoRawFd>) -> UnixFDList {
2117
let fds = fds.into_iter().map(|t| t.into_raw_fd()).collect::<Vec<_>>();
2218
unsafe {
2319
from_glib_full(ffi::g_unix_fd_list_new_from_array(

gio/src/unix_input_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl UnixInputStream {
2020
/// with `true` on this stream. At which point you may only do so when all references to this
2121
/// stream have been dropped.
2222
#[doc(alias = "g_unix_input_stream_new")]
23-
pub unsafe fn take_fd<T: IntoRawFd>(fd: T) -> UnixInputStream {
23+
pub unsafe fn take_fd(fd: impl IntoRawFd) -> UnixInputStream {
2424
let fd = fd.into_raw_fd();
2525
let close_fd = true.into_glib();
2626
InputStream::from_glib_full(ffi::g_unix_input_stream_new(fd, close_fd)).unsafe_cast()

gio/src/unix_output_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl UnixOutputStream {
2020
/// on this stream. At which point you may only do so when all references to this stream have
2121
/// been dropped.
2222
#[doc(alias = "g_unix_output_stream_new")]
23-
pub unsafe fn take_fd<T: IntoRawFd>(fd: T) -> UnixOutputStream {
23+
pub unsafe fn take_fd(fd: impl IntoRawFd) -> UnixOutputStream {
2424
let fd = fd.into_raw_fd();
2525
let close_fd = true.into_glib();
2626
OutputStream::from_glib_full(ffi::g_unix_output_stream_new(fd, close_fd)).unsafe_cast()

gio/src/win32_input_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Win32InputStream {
4848
/// with `true` on this stream. At which point you may only do so when all references to this
4949
/// stream have been dropped.
5050
#[doc(alias = "g_win32_input_stream_new")]
51-
pub unsafe fn take_handle<T: IntoRawHandle>(handle: T) -> Win32InputStream {
51+
pub unsafe fn take_handle(handle: impl IntoRawHandle) -> Win32InputStream {
5252
let handle = handle.into_raw_handle();
5353
let close_handle = true.into_glib();
5454
InputStream::from_glib_full(ffi::g_win32_input_stream_new(handle, close_handle))

gio/src/win32_output_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Win32OutputStream {
4848
/// with `true` on this stream. At which point you may only do so when all references to this
4949
/// stream have been dropped.
5050
#[doc(alias = "g_win32_output_stream_new")]
51-
pub unsafe fn take_handle<T: IntoRawHandle>(handle: T) -> Win32OutputStream {
51+
pub unsafe fn take_handle(handle: impl IntoRawHandle) -> Win32OutputStream {
5252
let handle = handle.into_raw_handle();
5353
let close_handle = true.into_glib();
5454
OutputStream::from_glib_full(ffi::g_win32_output_stream_new(handle, close_handle))

glib/src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ pub struct BoolError {
199199
}
200200

201201
impl BoolError {
202-
pub fn new<Msg: Into<Cow<'static, str>>>(
203-
message: Msg,
202+
pub fn new(
203+
message: impl Into<Cow<'static, str>>,
204204
filename: &'static str,
205205
function: &'static str,
206206
line: u32,
@@ -213,9 +213,9 @@ impl BoolError {
213213
}
214214
}
215215

216-
pub fn from_glib<Msg: Into<Cow<'static, str>>>(
216+
pub fn from_glib(
217217
b: ffi::gboolean,
218-
message: Msg,
218+
message: impl Into<Cow<'static, str>>,
219219
filename: &'static str,
220220
function: &'static str,
221221
line: u32,

glib/src/variant.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ impl Variant {
421421
///
422422
/// This function panics if not all variants are of type `T`.
423423
#[doc(alias = "g_variant_new_array")]
424-
pub fn array_from_iter<T: StaticVariantType, I: IntoIterator<Item = Variant>>(
425-
children: I,
424+
pub fn array_from_iter<T: StaticVariantType>(
425+
children: impl IntoIterator<Item = Variant>,
426426
) -> Self {
427427
Self::array_from_iter_with_type(&T::static_variant_type(), children)
428428
}
@@ -434,9 +434,9 @@ impl Variant {
434434
///
435435
/// This function panics if not all variants are of type `type_`.
436436
#[doc(alias = "g_variant_new_array")]
437-
pub fn array_from_iter_with_type<T: AsRef<Variant>, I: IntoIterator<Item = T>>(
437+
pub fn array_from_iter_with_type(
438438
type_: &VariantTy,
439-
children: I,
439+
children: impl IntoIterator<Item = impl AsRef<Variant>>,
440440
) -> Self {
441441
unsafe {
442442
let mut builder = mem::MaybeUninit::uninit();
@@ -1653,7 +1653,7 @@ tuple_impls! {
16531653

16541654
impl<T: ToVariant + StaticVariantType> FromIterator<T> for Variant {
16551655
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
1656-
Variant::array_from_iter::<T, _>(iter.into_iter().map(|v| v.to_variant()))
1656+
Variant::array_from_iter::<T>(iter.into_iter().map(|v| v.to_variant()))
16571657
}
16581658
}
16591659

@@ -2085,7 +2085,7 @@ mod tests {
20852085

20862086
#[test]
20872087
fn test_array_from_iter() {
2088-
let a = Variant::array_from_iter::<String, _>(
2088+
let a = Variant::array_from_iter::<String>(
20892089
["foo", "bar", "baz"].into_iter().map(|s| s.to_variant()),
20902090
);
20912091
assert_eq!(a.type_().as_str(), "as");

glib/src/variant_iter.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ mod tests {
216216

217217
#[test]
218218
fn test_variant_iter_array() {
219-
let v = Variant::array_from_iter::<String, _>([
219+
let v = Variant::array_from_iter::<String>([
220220
"foo".to_string().to_variant(),
221221
"bar".to_string().to_variant(),
222222
]);
@@ -255,7 +255,7 @@ mod tests {
255255

256256
#[test]
257257
fn test_variant_iter_nth() {
258-
let v = Variant::array_from_iter::<String, _>([
258+
let v = Variant::array_from_iter::<String>([
259259
"0".to_string().to_variant(),
260260
"1".to_string().to_variant(),
261261
"2".to_string().to_variant(),
@@ -287,7 +287,7 @@ mod tests {
287287

288288
#[test]
289289
fn test_variant_iter_count() {
290-
let v = Variant::array_from_iter::<String, _>([
290+
let v = Variant::array_from_iter::<String>([
291291
"0".to_string().to_variant(),
292292
"1".to_string().to_variant(),
293293
"2".to_string().to_variant(),
@@ -301,7 +301,7 @@ mod tests {
301301

302302
#[test]
303303
fn test_variant_iter_last() {
304-
let v = Variant::array_from_iter::<String, _>([
304+
let v = Variant::array_from_iter::<String>([
305305
"0".to_string().to_variant(),
306306
"1".to_string().to_variant(),
307307
"2".to_string().to_variant(),
@@ -318,7 +318,7 @@ mod tests {
318318

319319
#[test]
320320
fn test_variant_str_iter_nth() {
321-
let v = Variant::array_from_iter::<String, _>([
321+
let v = Variant::array_from_iter::<String>([
322322
"0".to_string().to_variant(),
323323
"1".to_string().to_variant(),
324324
"2".to_string().to_variant(),
@@ -341,7 +341,7 @@ mod tests {
341341

342342
#[test]
343343
fn test_variant_str_iter_count() {
344-
let v = Variant::array_from_iter::<String, _>([
344+
let v = Variant::array_from_iter::<String>([
345345
"0".to_string().to_variant(),
346346
"1".to_string().to_variant(),
347347
"2".to_string().to_variant(),
@@ -355,7 +355,7 @@ mod tests {
355355

356356
#[test]
357357
fn test_variant_str_iter_last() {
358-
let v = Variant::array_from_iter::<String, _>([
358+
let v = Variant::array_from_iter::<String>([
359359
"0".to_string().to_variant(),
360360
"1".to_string().to_variant(),
361361
"2".to_string().to_variant(),

0 commit comments

Comments
 (0)