Skip to content

Commit 7595f71

Browse files
committed
Port Unix*Stream::take_fd to safe-io
1 parent 4617cc6 commit 7595f71

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

gio/src/unix_input_stream.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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, IntoRawFd, RawFd};
4+
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
55

66
use glib::{prelude::*, translate::*};
77
#[cfg(all(not(unix), docsrs))]
@@ -12,16 +12,13 @@ use crate::{ffi, InputStream, UnixInputStream};
1212
impl UnixInputStream {
1313
// rustdoc-stripper-ignore-next
1414
/// Creates a new [`Self`] that takes ownership of the passed in fd.
15-
///
16-
/// # Safety
17-
/// You must not close the fd unless you've previously called [`UnixInputStreamExtManual::set_close_fd`]
18-
/// with `true` on this stream. At which point you may only do so when all references to this
19-
/// stream have been dropped.
2015
#[doc(alias = "g_unix_input_stream_new")]
21-
pub unsafe fn take_fd(fd: impl IntoRawFd) -> UnixInputStream {
16+
pub fn take_fd(fd: OwnedFd) -> UnixInputStream {
2217
let fd = fd.into_raw_fd();
2318
let close_fd = true.into_glib();
24-
InputStream::from_glib_full(ffi::g_unix_input_stream_new(fd, close_fd)).unsafe_cast()
19+
unsafe {
20+
InputStream::from_glib_full(ffi::g_unix_input_stream_new(fd, close_fd)).unsafe_cast()
21+
}
2522
}
2623

2724
// rustdoc-stripper-ignore-next

gio/src/unix_output_stream.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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, IntoRawFd, RawFd};
4+
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
55

66
use glib::{prelude::*, translate::*};
77
#[cfg(all(not(unix), docsrs))]
@@ -12,16 +12,13 @@ use crate::{ffi, OutputStream, UnixOutputStream};
1212
impl UnixOutputStream {
1313
// rustdoc-stripper-ignore-next
1414
/// Creates a new [`Self`] that takes ownership of the passed in fd.
15-
///
16-
/// # Safety
17-
/// You must not close the fd unless you've previously called [`UnixOutputStreamExtManual::set_close_fd`]
18-
/// on this stream. At which point you may only do so when all references to this stream have
19-
/// been dropped.
2015
#[doc(alias = "g_unix_output_stream_new")]
21-
pub unsafe fn take_fd(fd: impl IntoRawFd) -> UnixOutputStream {
16+
pub fn take_fd(fd: OwnedFd) -> UnixOutputStream {
2217
let fd = fd.into_raw_fd();
2318
let close_fd = true.into_glib();
24-
OutputStream::from_glib_full(ffi::g_unix_output_stream_new(fd, close_fd)).unsafe_cast()
19+
unsafe {
20+
OutputStream::from_glib_full(ffi::g_unix_output_stream_new(fd, close_fd)).unsafe_cast()
21+
}
2522
}
2623

2724
// rustdoc-stripper-ignore-next

0 commit comments

Comments
 (0)