Skip to content

Commit c96b56c

Browse files
authored
Merge pull request #915 from jf2048/file-descriptor-based
gio: bind GFileDescriptorBased
2 parents 66237a7 + e4a7232 commit c96b56c

File tree

8 files changed

+74
-38
lines changed

8 files changed

+74
-38
lines changed

gio/Gir.toml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,12 @@ status = "generate"
783783
# Better API with `IntoIter`
784784
ignore = true
785785

786+
[[object]]
787+
name = "Gio.FileDescriptorBased"
788+
status = "manual"
789+
cfg_condition = "unix"
790+
manual_traits = ["FileDescriptorBasedExtManual"]
791+
786792
[[object]]
787793
name = "Gio.FileEnumerator"
788794
status = "generate"
@@ -1480,9 +1486,8 @@ manual_traits = ["UnixInputStreamExtManual"]
14801486

14811487
[[object.function]]
14821488
name = "get_fd"
1483-
# has to use RawFd
1484-
manual = true
1485-
doc_trait_name = "UnixInputStreamExtManual"
1489+
# conflicts with as FileDescriptorBased::fd
1490+
ignore = true
14861491

14871492
[[object.property]]
14881493
name = "fd"
@@ -1551,9 +1556,8 @@ manual_traits = ["UnixOutputStreamExtManual"]
15511556

15521557
[[object.function]]
15531558
name = "get_fd"
1554-
# has to use RawFd
1555-
manual = true
1556-
doc_trait_name = "UnixOutputStreamExtManual"
1559+
# conflicts with as FileDescriptorBased::fd
1560+
ignore = true
15571561

15581562
[[object.property]]
15591563
name = "fd"

gio/src/auto/unix_input_stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// from gir-files (https://github.com/gtk-rs/gir-files)
33
// DO NOT EDIT
44

5-
use crate::{InputStream, PollableInputStream};
5+
use crate::{FileDescriptorBased, InputStream, PollableInputStream};
66
use glib::{prelude::*, translate::*};
77
use std::fmt;
88

99
glib::wrapper! {
1010
#[doc(alias = "GUnixInputStream")]
11-
pub struct UnixInputStream(Object<ffi::GUnixInputStream, ffi::GUnixInputStreamClass>) @extends InputStream, @implements PollableInputStream;
11+
pub struct UnixInputStream(Object<ffi::GUnixInputStream, ffi::GUnixInputStreamClass>) @extends InputStream, @implements FileDescriptorBased, PollableInputStream;
1212

1313
match fn {
1414
type_ => || ffi::g_unix_input_stream_get_type(),

gio/src/auto/unix_output_stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// from gir-files (https://github.com/gtk-rs/gir-files)
33
// DO NOT EDIT
44

5-
use crate::{OutputStream, PollableOutputStream};
5+
use crate::{FileDescriptorBased, OutputStream, PollableOutputStream};
66
use glib::{prelude::*, translate::*};
77
use std::fmt;
88

99
glib::wrapper! {
1010
#[doc(alias = "GUnixOutputStream")]
11-
pub struct UnixOutputStream(Object<ffi::GUnixOutputStream, ffi::GUnixOutputStreamClass>) @extends OutputStream, @implements PollableOutputStream;
11+
pub struct UnixOutputStream(Object<ffi::GUnixOutputStream, ffi::GUnixOutputStreamClass>) @extends OutputStream, @implements FileDescriptorBased, PollableOutputStream;
1212

1313
match fn {
1414
type_ => || ffi::g_unix_output_stream_get_type(),

gio/src/file_descriptor_based.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Take a look at the license at the top of the repository in the LICENSE file.
2+
3+
#[cfg(unix)]
4+
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
5+
6+
use glib::{prelude::*, translate::*};
7+
#[cfg(all(not(unix), feature = "dox"))]
8+
use socket::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
9+
use std::fmt;
10+
11+
glib::wrapper! {
12+
#[doc(alias = "GFileDescriptorBased")]
13+
pub struct FileDescriptorBased(Interface<ffi::GFileDescriptorBased, ffi::GFileDescriptorBasedIface>);
14+
15+
match fn {
16+
type_ => || ffi::g_file_descriptor_based_get_type(),
17+
}
18+
}
19+
20+
impl FileDescriptorBased {
21+
pub const NONE: Option<&'static FileDescriptorBased> = None;
22+
}
23+
24+
impl AsRawFd for FileDescriptorBased {
25+
fn as_raw_fd(&self) -> RawFd {
26+
unsafe { ffi::g_file_descriptor_based_get_fd(self.to_glib_none().0) as _ }
27+
}
28+
}
29+
30+
pub trait FileDescriptorBasedExtManual: 'static {
31+
#[doc(alias = "g_file_descriptor_based_get_fd")]
32+
#[doc(alias = "get_fd")]
33+
fn fd<T: FromRawFd>(&self) -> T;
34+
}
35+
36+
impl<O: IsA<FileDescriptorBased>> FileDescriptorBasedExtManual for O {
37+
fn fd<T: FromRawFd>(&self) -> T {
38+
unsafe {
39+
T::from_raw_fd(ffi::g_file_descriptor_based_get_fd(
40+
self.as_ref().to_glib_none().0,
41+
))
42+
}
43+
}
44+
}
45+
46+
impl fmt::Display for FileDescriptorBased {
47+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48+
f.write_str("FileDescriptorBased")
49+
}
50+
}

gio/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ pub use crate::file_attribute_info::FileAttributeInfo;
4747
mod file_attribute_info_list;
4848
mod file_attribute_matcher;
4949
pub use crate::file_attribute_matcher::FileAttributematcherIter;
50+
#[cfg(any(unix, feature = "dox"))]
51+
mod file_descriptor_based;
52+
#[cfg(any(unix, feature = "dox"))]
53+
pub use file_descriptor_based::FileDescriptorBased;
5054
mod file_enumerator;
5155
mod file_info;
5256
mod flags;

gio/src/prelude.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub use crate::debug_controller_dbus::DebugControllerDBusExtManual;
1515
#[cfg(any(all(not(windows), not(target_os = "macos")), feature = "dox"))]
1616
pub use crate::desktop_app_info::DesktopAppInfoExtManual;
1717
#[cfg(any(unix, feature = "dox"))]
18+
pub use crate::file_descriptor_based::FileDescriptorBasedExtManual;
19+
#[cfg(any(unix, feature = "dox"))]
1820
pub use crate::unix_fd_list::UnixFDListExtManual;
1921
#[cfg(any(unix, feature = "dox"))]
2022
pub use crate::unix_fd_message::UnixFDMessageExtManual;

gio/src/unix_input_stream.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

33
#[cfg(unix)]
4-
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
4+
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
55

66
use glib::{prelude::*, translate::*};
77
#[cfg(all(not(unix), feature = "dox"))]
8-
use socket::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
8+
use socket::{AsRawFd, IntoRawFd, RawFd};
99

1010
use crate::{InputStream, UnixInputStream};
1111

@@ -44,10 +44,6 @@ impl AsRawFd for UnixInputStream {
4444
}
4545

4646
pub trait UnixInputStreamExtManual: Sized {
47-
#[doc(alias = "g_unix_input_stream_get_fd")]
48-
#[doc(alias = "get_fd")]
49-
fn fd<T: FromRawFd>(&self) -> T;
50-
5147
// rustdoc-stripper-ignore-next
5248
/// Sets whether the fd of this stream will be closed when the stream is closed.
5349
///
@@ -59,14 +55,6 @@ pub trait UnixInputStreamExtManual: Sized {
5955
}
6056

6157
impl<O: IsA<UnixInputStream>> UnixInputStreamExtManual for O {
62-
fn fd<T: FromRawFd>(&self) -> T {
63-
unsafe {
64-
T::from_raw_fd(ffi::g_unix_input_stream_get_fd(
65-
self.as_ref().to_glib_none().0,
66-
))
67-
}
68-
}
69-
7058
unsafe fn set_close_fd(&self, close_fd: bool) {
7159
ffi::g_unix_input_stream_set_close_fd(self.as_ref().to_glib_none().0, close_fd.into_glib());
7260
}

gio/src/unix_output_stream.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

33
#[cfg(unix)]
4-
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
4+
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
55

66
use glib::{prelude::*, translate::*};
77
#[cfg(all(not(unix), feature = "dox"))]
8-
use socket::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
8+
use socket::{AsRawFd, IntoRawFd, RawFd};
99

1010
use crate::{OutputStream, UnixOutputStream};
1111

@@ -44,10 +44,6 @@ impl AsRawFd for UnixOutputStream {
4444
}
4545

4646
pub trait UnixOutputStreamExtManual: Sized {
47-
#[doc(alias = "g_unix_output_stream_get_fd")]
48-
#[doc(alias = "get_fd")]
49-
fn fd<T: FromRawFd>(&self) -> T;
50-
5147
// rustdoc-stripper-ignore-next
5248
/// Sets whether the fd of this stream will be closed when the stream is closed.
5349
///
@@ -59,14 +55,6 @@ pub trait UnixOutputStreamExtManual: Sized {
5955
}
6056

6157
impl<O: IsA<UnixOutputStream>> UnixOutputStreamExtManual for O {
62-
fn fd<T: FromRawFd>(&self) -> T {
63-
unsafe {
64-
T::from_raw_fd(ffi::g_unix_output_stream_get_fd(
65-
self.as_ref().to_glib_none().0,
66-
))
67-
}
68-
}
69-
7058
unsafe fn set_close_fd(&self, close_fd: bool) {
7159
ffi::g_unix_output_stream_set_close_fd(
7260
self.as_ref().to_glib_none().0,

0 commit comments

Comments
 (0)