pub trait AsRawFd {
// Required method
fn as_raw_fd(&self) -> i32;
}
Available on Unix only.
Expand description
A trait to extract the raw file descriptor from an underlying object.
This is only available on unix and WASI platforms and must be imported in
order to call the method. Windows platforms have a corresponding
AsRawHandle
and AsRawSocket
set of traits.
Required Methods§
1.0.0 · Sourcefn as_raw_fd(&self) -> i32
fn as_raw_fd(&self) -> i32
Extracts the raw file descriptor.
This function is typically used to borrow an owned file descriptor. When used in this way, this method does not pass ownership of the raw file descriptor to the caller, and the file descriptor is only guaranteed to be valid while the original object has not yet been destroyed.
However, borrowing is not strictly required. See [AsFd::as_fd
]
for an API which strictly borrows a file descriptor.
§Example
use std::fs::File;
#[cfg(any(unix, target_os = "wasi"))]
use std::os::fd::{AsRawFd, RawFd};
let mut f = File::open("foo.txt")?;
// Note that `raw_fd` is only valid as long as `f` exists.
#[cfg(any(unix, target_os = "wasi"))]
let raw_fd: RawFd = f.as_raw_fd();
Implementors§
impl AsRawFd for i32
impl AsRawFd for wiwi::prelude::File
impl AsRawFd for PipeReader
impl AsRawFd for PipeWriter
impl AsRawFd for wiwi::prelude::std::io::Stderr
impl AsRawFd for wiwi::prelude::std::io::Stdin
impl AsRawFd for wiwi::prelude::std::io::Stdout
impl AsRawFd for wiwi::prelude::std::net::TcpListener
impl AsRawFd for wiwi::prelude::std::net::TcpStream
impl AsRawFd for wiwi::prelude::std::net::UdpSocket
impl AsRawFd for wiwi::prelude::std::process::ChildStderr
impl AsRawFd for wiwi::prelude::std::process::ChildStdin
impl AsRawFd for wiwi::prelude::std::process::ChildStdout
impl AsRawFd for BorrowedFd<'_>
impl AsRawFd for OwnedFd
impl AsRawFd for PidFd
impl AsRawFd for wiwi::prelude::std::os::unix::net::UnixDatagram
impl AsRawFd for wiwi::prelude::std::os::unix::net::UnixListener
impl AsRawFd for wiwi::prelude::std::os::unix::net::UnixStream
impl AsRawFd for ChildStderr
impl AsRawFd for ChildStdin
impl AsRawFd for ChildStdout
impl AsRawFd for File
impl AsRawFd for Poll
Available on non-
mio_unsupported_force_poll_poll
and neither target_os="espidf"
nor Fuchsia nor Haiku nor HermitCore nor target_os="hurd"
nor target_os="nto"
nor Solaris nor target_os="vita"
only.impl AsRawFd for Receiver
impl AsRawFd for Receiver
Available on crate feature
os-ext
only.impl AsRawFd for Registry
Available on non-
mio_unsupported_force_poll_poll
and neither target_os="espidf"
nor Haiku nor Fuchsia nor HermitCore nor target_os="hurd"
nor target_os="nto"
nor Solaris nor target_os="vita"
only.impl AsRawFd for Sender
impl AsRawFd for Sender
Available on crate feature
os-ext
only.impl AsRawFd for Socket
impl AsRawFd for Stderr
impl AsRawFd for Stdin
impl AsRawFd for Stdout
impl AsRawFd for TcpListener
impl AsRawFd for TcpListener
Available on Unix or HermitCore or WASI only.
impl AsRawFd for TcpSocket
Available on
docsrs
or Unix only.impl AsRawFd for TcpStream
impl AsRawFd for TcpStream
Available on Unix or HermitCore or WASI only.
impl AsRawFd for UdpSocket
impl AsRawFd for UdpSocket
Available on Unix or HermitCore or WASI only.
impl AsRawFd for UnixDatagram
impl AsRawFd for UnixDatagram
impl AsRawFd for UnixListener
impl AsRawFd for UnixListener
impl AsRawFd for UnixSocket
impl AsRawFd for UnixStream
impl AsRawFd for UnixStream
impl<'a> AsRawFd for StderrLock<'a>
impl<'a> AsRawFd for StdinLock<'a>
impl<'a> AsRawFd for StdoutLock<'a>
impl<T> AsRawFd for UniqueRc<T>
impl<T> AsRawFd for Arc<T>where
T: AsRawFd,
This impl allows implementing traits that require AsRawFd
on Arc.
use std::net::UdpSocket;
use std::sync::Arc;
trait MyTrait: AsRawFd {
}
impl MyTrait for Arc<UdpSocket> {}
impl MyTrait for Box<UdpSocket> {}