On this page
Trait std::os::fd::AsFd
pub trait AsFd {
// Required method
fn as_fd(&self) -> BorrowedFd<'_>;
}
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) -> 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
impl AsFd for File
impl AsFd for Stderr
impl AsFd for Stdin
impl AsFd for Stdout
impl AsFd for TcpListener
impl AsFd for TcpStream
impl AsFd for UdpSocket
impl AsFd for ChildStderrAvailable on Unix only.
impl AsFd for ChildStdinAvailable on Unix only.
impl AsFd for ChildStdoutAvailable on Unix only.
impl AsFd for PidFdAvailable on Linux only.
impl AsFd for UnixDatagramAvailable on Unix only.
impl AsFd for UnixListenerAvailable on Unix only.
impl AsFd for UnixStreamAvailable on Unix only.
impl AsFd for BorrowedFd<'_>
impl AsFd for OwnedFd
impl<'a> AsFd for StderrLock<'a>
impl<'a> AsFd for StdinLock<'a>
impl<'a> AsFd for StdoutLock<'a>
impl<T: AsFd> AsFd for &T
impl<T: AsFd> AsFd for &mut T
impl<T: AsFd> AsFd for Box<T>
impl<T: AsFd> AsFd for Rc<T>
impl<T: AsFd> 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> {}
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/os/fd/trait.AsFd.html