Trait AsRawFd

1.66.0 · Source
pub trait AsRawFd {
    // Required method
    fn as_raw_fd(&self) -> i32;
}
Available on Unix or HermitCore or WASI 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 · 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();

Implementors§

1.48.0 · Source§

impl AsRawFd for i32

1.0.0 · Source§

impl AsRawFd for wiwi::prelude::File

Source§

impl AsRawFd for PipeReader

Source§

impl AsRawFd for PipeWriter

1.21.0 · Source§

impl AsRawFd for wiwi::prelude::std::io::Stderr

1.21.0 · Source§

impl AsRawFd for wiwi::prelude::std::io::Stdin

1.21.0 · Source§

impl AsRawFd for wiwi::prelude::std::io::Stdout

1.0.0 · Source§

impl AsRawFd for wiwi::prelude::std::net::TcpListener

1.0.0 · Source§

impl AsRawFd for wiwi::prelude::std::net::TcpStream

1.0.0 · Source§

impl AsRawFd for wiwi::prelude::std::net::UdpSocket

1.2.0 · Source§

impl AsRawFd for wiwi::prelude::std::process::ChildStderr

1.2.0 · Source§

impl AsRawFd for wiwi::prelude::std::process::ChildStdin

1.2.0 · Source§

impl AsRawFd for wiwi::prelude::std::process::ChildStdout

Source§

impl AsRawFd for PidFd

1.10.0 · Source§

impl AsRawFd for wiwi::prelude::std::os::unix::net::UnixDatagram

1.10.0 · Source§

impl AsRawFd for wiwi::prelude::std::os::unix::net::UnixListener

1.10.0 · Source§

impl AsRawFd for wiwi::prelude::std::os::unix::net::UnixStream

1.63.0 · Source§

impl AsRawFd for BorrowedFd<'_>

1.63.0 · Source§

impl AsRawFd for OwnedFd

§

impl AsRawFd for ChildStderr

§

impl AsRawFd for ChildStdin

§

impl AsRawFd for ChildStdout

§

impl AsRawFd for File

Available on Unix only.
§

impl AsRawFd for Poll

Available on Unix and 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 Unix and 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

§

impl AsRawFd for TcpSocket

Available on docsrs or Unix only.
§

impl AsRawFd for TcpStream

§

impl AsRawFd for TcpStream

§

impl AsRawFd for UdpSocket

§

impl AsRawFd for UdpSocket

§

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

1.35.0 · Source§

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

1.35.0 · Source§

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

1.35.0 · Source§

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

Source§

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

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

§

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