AsFd in std::os::unix::io - Rust (original) (raw)

🔬 This is a nightly-only experimental API. (io_safety #87074)

This is supported on Unix only.

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 andAsSocket set of traits.

🔬 This is a nightly-only experimental API. (io_safety #87074)

Borrows the file descriptor.

use std::fs::File;

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

Run

impl AsFd for PidFd

This is supported on Linux only.