gio/
unix_output_stream.rs
1#[cfg(unix)]
4use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
5
6use glib::{prelude::*, translate::*};
7#[cfg(all(not(unix), docsrs))]
8use socket::{AsRawFd, IntoRawFd, RawFd};
9
10use crate::{ffi, OutputStream, UnixOutputStream};
11
12impl UnixOutputStream {
13 #[doc(alias = "g_unix_output_stream_new")]
21 pub unsafe fn take_fd(fd: impl IntoRawFd) -> UnixOutputStream {
22 let fd = fd.into_raw_fd();
23 let close_fd = true.into_glib();
24 OutputStream::from_glib_full(ffi::g_unix_output_stream_new(fd, close_fd)).unsafe_cast()
25 }
26
27 #[doc(alias = "g_unix_output_stream_new")]
33 pub unsafe fn with_fd<T: AsRawFd>(fd: T) -> UnixOutputStream {
34 let fd = fd.as_raw_fd();
35 let close_fd = false.into_glib();
36 OutputStream::from_glib_full(ffi::g_unix_output_stream_new(fd, close_fd)).unsafe_cast()
37 }
38}
39
40impl AsRawFd for UnixOutputStream {
41 fn as_raw_fd(&self) -> RawFd {
42 unsafe { ffi::g_unix_output_stream_get_fd(self.to_glib_none().0) as _ }
43 }
44}
45
46mod sealed {
47 pub trait Sealed {}
48 impl<T: super::IsA<super::UnixOutputStream>> Sealed for T {}
49}
50
51pub trait UnixOutputStreamExtManual: sealed::Sealed + IsA<UnixOutputStream> + Sized {
52 #[doc(alias = "g_unix_output_stream_set_close_fd")]
59 unsafe fn set_close_fd(&self, close_fd: bool) {
60 ffi::g_unix_output_stream_set_close_fd(
61 self.as_ref().to_glib_none().0,
62 close_fd.into_glib(),
63 );
64 }
65}
66
67impl<O: IsA<UnixOutputStream>> UnixOutputStreamExtManual for O {}