std::os::fd

Trait AsFd

1.66.0 · Source
pub trait AsFd {
    // Required method
    fn as_fd(&self) -> BorrowedFd<'_>;
}
Expand description

A trait to borrow the file descriptor from an underlying object.

This is only available on unix platforms and must be imported in order to call the method. Windows platforms have a corresponding AsHandle and AsSocket set of traits.

Required Methods§

1.63.0 · Source

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor.

§Example
use std::fs::File;

let mut f = File::open("foo.txt")?;
let borrowed_fd: BorrowedFd<'_> = f.as_fd();

Implementors§

1.63.0 · Source§

impl AsFd for File

1.63.0 · Source§

impl AsFd for Stderr

1.63.0 · Source§

impl AsFd for Stdin

1.63.0 · Source§

impl AsFd for Stdout

1.63.0 · Source§

impl AsFd for TcpListener

1.63.0 · Source§

impl AsFd for TcpStream

1.63.0 · Source§

impl AsFd for UdpSocket

Source§

impl AsFd for PipeReader

Source§

impl AsFd for PipeWriter

1.63.0 · Source§

impl AsFd for ChildStderr

Available on Unix only.
1.63.0 · Source§

impl AsFd for ChildStdin

Available on Unix only.
1.63.0 · Source§

impl AsFd for ChildStdout

Available on Unix only.
Source§

impl AsFd for PidFd

Available on Linux only.
1.63.0 · Source§

impl AsFd for UnixDatagram

Available on Unix only.
1.63.0 · Source§

impl AsFd for UnixListener

Available on Unix only.
1.63.0 · Source§

impl AsFd for UnixStream

Available on Unix only.
1.63.0 · Source§

impl AsFd for BorrowedFd<'_>

1.63.0 · Source§

impl AsFd for OwnedFd

1.63.0 · Source§

impl<'a> AsFd for StderrLock<'a>

1.63.0 · Source§

impl<'a> AsFd for StdinLock<'a>

1.63.0 · Source§

impl<'a> AsFd for StdoutLock<'a>

1.63.0 · Source§

impl<T: AsFd + ?Sized> AsFd for &T

1.63.0 · Source§

impl<T: AsFd + ?Sized> AsFd for &mut T

1.64.0 · Source§

impl<T: AsFd + ?Sized> AsFd for Box<T>

1.69.0 · Source§

impl<T: AsFd + ?Sized> AsFd for Rc<T>

Source§

impl<T: AsFd + ?Sized> AsFd for UniqueRc<T>

1.64.0 · Source§

impl<T: AsFd + ?Sized> AsFd for Arc<T>

This impl allows implementing traits that require AsFd on Arc.

use std::net::UdpSocket;
use std::sync::Arc;

trait MyTrait: AsFd {}
impl MyTrait for Arc<UdpSocket> {}
impl MyTrait for Box<UdpSocket> {}