gio_unix/
file_descriptor_based.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, RawFd};
4
5use crate::{ffi, FileDescriptorBased};
6use glib::{prelude::*, translate::*};
7
8impl AsRawFd for FileDescriptorBased {
9    fn as_raw_fd(&self) -> RawFd {
10        unsafe { ffi::g_file_descriptor_based_get_fd(self.to_glib_none().0) as _ }
11    }
12}
13
14impl AsFd for FileDescriptorBased {
15    fn as_fd(&self) -> BorrowedFd<'_> {
16        unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
17    }
18}
19
20pub trait FileDescriptorBasedExtManual: IsA<FileDescriptorBased> + 'static {
21    /// Gets the underlying file descriptor.
22    ///
23    /// # Returns
24    ///
25    /// The file descriptor
26    #[doc(alias = "g_file_descriptor_based_get_fd")]
27    #[doc(alias = "get_fd")]
28    fn fd<T: FromRawFd>(&self) -> T {
29        unsafe {
30            T::from_raw_fd(ffi::g_file_descriptor_based_get_fd(
31                self.as_ref().to_glib_none().0,
32            ))
33        }
34    }
35}
36
37impl<O: IsA<FileDescriptorBased>> FileDescriptorBasedExtManual for O {}