gio/
unix_input_stream.rs
1#[cfg(unix)]
4use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, IntoRawFd, OwnedFd, RawFd};
5
6use glib::{prelude::*, translate::*};
7#[cfg(all(not(unix), docsrs))]
8use socket::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
9
10use crate::{ffi, InputStream, UnixInputStream};
11
12impl UnixInputStream {
13 #[doc(alias = "g_unix_input_stream_new")]
16 pub fn take_fd(fd: OwnedFd) -> UnixInputStream {
17 let fd = fd.into_raw_fd();
18 let close_fd = true.into_glib();
19 unsafe {
20 InputStream::from_glib_full(ffi::g_unix_input_stream_new(fd, close_fd)).unsafe_cast()
21 }
22 }
23
24 #[doc(alias = "g_unix_input_stream_new")]
30 pub unsafe fn with_fd<T: AsRawFd>(fd: T) -> UnixInputStream {
31 let fd = fd.as_raw_fd();
32 let close_fd = false.into_glib();
33 InputStream::from_glib_full(ffi::g_unix_input_stream_new(fd, close_fd)).unsafe_cast()
34 }
35}
36
37impl AsRawFd for UnixInputStream {
38 fn as_raw_fd(&self) -> RawFd {
39 unsafe { ffi::g_unix_input_stream_get_fd(self.to_glib_none().0) as _ }
40 }
41}
42
43impl AsFd for UnixInputStream {
44 fn as_fd(&self) -> BorrowedFd<'_> {
45 unsafe {
46 let raw_fd = self.as_raw_fd();
47 BorrowedFd::borrow_raw(raw_fd)
48 }
49 }
50}
51
52pub trait UnixInputStreamExtManual: IsA<UnixInputStream> + Sized {
53 #[doc(alias = "g_unix_input_stream_set_close_fd")]
60 unsafe fn set_close_fd(&self, close_fd: bool) {
61 ffi::g_unix_input_stream_set_close_fd(self.as_ref().to_glib_none().0, close_fd.into_glib());
62 }
63}
64
65impl<O: IsA<UnixInputStream>> UnixInputStreamExtManual for O {}