# Trait rustix::fd::AsFd

1.63.0 · source · [−]

    pub trait AsFd {
        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

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

source

### impl AsFd for File

source

### impl AsFd for Stderr

source

### impl AsFd for Stdin

source

### impl AsFd for Stdout

source

### impl AsFd for TcpListener

source

### impl AsFd for TcpStream

source

### impl AsFd for UdpSocket

source

### impl AsFd for PidFd

source

### impl AsFd for UnixDatagram

source

### impl AsFd for UnixListener

source

### impl AsFd for UnixStream

source

### impl AsFd for ChildStderr

source

### impl AsFd for ChildStdin

source

### impl AsFd for ChildStdout

source

### impl AsFd for BorrowedFd<'_>

source

### impl AsFd for OwnedFd

source

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

source

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

source

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

source

### impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> AsFd for Epoll<Owning<'context, T>>

source

### impl<'fd> AsFd for PollFd<'fd>

source

### impl<T> AsFd for &T where
T: AsFd,

source

### impl<T> AsFd for &mut T where
T: AsFd,

1.64.0 · source

### impl<T> AsFd for Box<T, Global> where
T: AsFd,

1.64.0 · source

### impl<T> AsFd for Arc<T> where
T: AsFd,

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