Skip to main content

AsRawFd

Trait AsRawFd 

1.0.0 · Source
pub trait AsRawFd {
    // Required method
    fn as_raw_fd(&self) -> i32;
}
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 · Source

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();

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

1.48.0 · Source§

impl AsRawFd for i32

Source§

impl AsRawFd for otter_nodejs_tests::fs::Dir

1.0.0 · Source§

impl AsRawFd for std::net::tcp::TcpListener

1.0.0 · Source§

impl AsRawFd for std::net::tcp::TcpStream

1.0.0 · Source§

impl AsRawFd for std::net::udp::UdpSocket

Source§

impl AsRawFd for PidFd

1.2.0 · Source§

impl AsRawFd for ChildStderr

1.2.0 · Source§

impl AsRawFd for ChildStdin

1.2.0 · Source§

impl AsRawFd for ChildStdout

Source§

impl AsRawFd for Term

Available on Unix, or WASI and WASIp1 only.
Source§

impl AsRawFd for inotify::inotify::Inotify

Source§

impl AsRawFd for mio::net::tcp::listener::TcpListener

Available on Unix or Hermit or WASI only.
Source§

impl AsRawFd for mio::net::tcp::stream::TcpStream

Available on Unix or Hermit or WASI only.
Source§

impl AsRawFd for mio::net::tcp::TcpListener

Available on Unix and non-Fuchsia only.
Source§

impl AsRawFd for mio::net::tcp::TcpStream

Available on Unix and non-Fuchsia only.
Source§

impl AsRawFd for mio::net::udp::UdpSocket

Available on Unix and non-Fuchsia only.
Source§

impl AsRawFd for mio::net::udp::UdpSocket

Available on Unix or Hermit or WASI only.
Source§

impl AsRawFd for mio::net::uds::datagram::UnixDatagram

Source§

impl AsRawFd for mio::net::uds::listener::UnixListener

Source§

impl AsRawFd for mio::net::uds::stream::UnixStream

Source§

impl AsRawFd for mio::poll::Poll

Available on Unix and non-Fuchsia only.
Source§

impl AsRawFd for mio::poll::Poll

Available on Unix and non-mio_unsupported_force_poll_poll and neither Solaris nor Play Station Vita only.
Source§

impl AsRawFd for mio::poll::Poll

Available on Unix and non-mio_unsupported_force_poll_poll and neither AIX nor ESP-IDF nor Fuchsia nor Haiku nor Hermit nor GNU/Hurd nor QNX Neutrino nor Solaris nor Play Station Vita nor Cygwin only.
Source§

impl AsRawFd for mio::poll::Registry

Available on Unix and non-mio_unsupported_force_poll_poll and neither Solaris nor Play Station Vita only.
Source§

impl AsRawFd for mio::poll::Registry

Available on Unix and non-mio_unsupported_force_poll_poll and neither AIX nor ESP-IDF nor Haiku nor Fuchsia nor Hermit nor GNU/Hurd nor QNX Neutrino nor Solaris nor Play Station Vita nor Cygwin only.
Source§

impl AsRawFd for mio::sys::unix::pipe::Receiver

Available on crate feature os-ext only.
Source§

impl AsRawFd for mio::sys::unix::pipe::Receiver

Available on crate feature os-ext only.
Source§

impl AsRawFd for mio::sys::unix::pipe::Sender

Available on crate feature os-ext only.
Source§

impl AsRawFd for mio::sys::unix::pipe::Sender

Available on crate feature os-ext only.
Source§

impl AsRawFd for TcpBuilder

Source§

impl AsRawFd for UdpBuilder

Source§

impl AsRawFd for Handle

Source§

impl AsRawFd for socket2::socket::Socket

Source§

impl AsRawFd for socket2::socket::Socket

Source§

impl AsRawFd for tokio::fs::file::File

Available on Unix only.
Source§

impl AsRawFd for tokio::net::tcp::listener::TcpListener

Source§

impl AsRawFd for TcpSocket

Available on docsrs, or Unix, or WASI only.
Source§

impl AsRawFd for tokio::net::tcp::stream::TcpStream

Source§

impl AsRawFd for tokio::net::udp::UdpSocket

Source§

impl AsRawFd for tokio::net::unix::datagram::socket::UnixDatagram

Source§

impl AsRawFd for tokio::net::unix::listener::UnixListener

Source§

impl AsRawFd for tokio::net::unix::pipe::Receiver

Source§

impl AsRawFd for tokio::net::unix::pipe::Sender

Source§

impl AsRawFd for UnixSocket

Source§

impl AsRawFd for tokio::net::unix::stream::UnixStream

1.87.0 · Source§

impl AsRawFd for PipeReader

Available on non-Trusty only.
1.87.0 · Source§

impl AsRawFd for PipeWriter

Available on non-Trusty only.
1.21.0 · Source§

impl AsRawFd for Stderr

1.21.0 · Source§

impl AsRawFd for Stdin

Available on non-Trusty only.
1.21.0 · Source§

impl AsRawFd for Stdout

Source§

impl AsRawFd for otter_nodejs_tests::nix::dir::Dir

Source§

impl AsRawFd for OwningIter

The file descriptor continues to be owned by the OwningIter, so callers must not keep a RawFd after the OwningIter is dropped.

Source§

impl AsRawFd for PollFd

Source§

impl AsRawFd for PtyMaster

Source§

impl AsRawFd for otter_nodejs_tests::nix::sys::inotify::Inotify

Source§

impl AsRawFd for SignalFd

Source§

impl AsRawFd for TimerFd

Source§

impl AsRawFd for Fd

1.0.0 · Source§

impl AsRawFd for otter_nodejs_tests::File

Available on non-Trusty only.
1.10.0 · Source§

impl AsRawFd for otter_nodejs_tests::UnixStream

Source§

impl AsRawFd for NonblockingUnixSeqpacketConn

Source§

impl AsRawFd for NonblockingUnixSeqpacketListener

Source§

impl AsRawFd for UnixSeqpacketConn

Source§

impl AsRawFd for UnixSeqpacketListener

1.63.0 · Source§

impl AsRawFd for BorrowedFd<'_>

1.63.0 · Source§

impl AsRawFd for OwnedFd

1.10.0 · Source§

impl AsRawFd for otter_nodejs_tests::unix::net::UnixDatagram

1.10.0 · Source§

impl AsRawFd for otter_nodejs_tests::unix::net::UnixListener

1.35.0 · Source§

impl<'a> AsRawFd for StderrLock<'a>

1.35.0 · Source§

impl<'a> AsRawFd for StdinLock<'a>

Available on non-Trusty only.
1.35.0 · Source§

impl<'a> AsRawFd for StdoutLock<'a>

Source§

impl<F> AsRawFd for NamedTempFile<F>
where F: AsRawFd,

Available on Unix or WASI only.
Source§

impl<S> AsRawFd for TlsStream<S>
where S: AsRawFd,

Available on Unix only.
1.63.0 · Source§

impl<T> AsRawFd for Box<T>
where T: AsRawFd,

1.69.0 · Source§

impl<T> AsRawFd for Rc<T>
where T: AsRawFd,

Source§

impl<T> AsRawFd for UniqueRc<T>
where T: AsRawFd + ?Sized,

Source§

impl<T> AsRawFd for AsyncFd<T>
where T: AsRawFd,

1.63.0 · Source§

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> {}