Trait AsFd

trait AsFd

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

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

Borrows the file descriptor.

Example

use std::fs::File;
# use std::io;
# #[cfg(any(unix, target_os = "wasi"))]
# use std::os::fd::{AsFd, BorrowedFd};

let mut f = File::open("foo.txt")?;
# #[cfg(any(unix, target_os = "wasi"))]
let borrowed_fd: BorrowedFd<'_> = f.as_fd();
# Ok::<(), io::Error>(())

Implementors