Trait std::os::fd::AsFd

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

一个 trait 来借用来自底层对象的文件描述符。

这仅在 unix 平台上可用,并且必须导入才能调用该方法。 Windows 平台有相应的 AsHandleAsSocket 的 traits 集合。

Required Methods§

source

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

借用文件描述符。

Example
use std::fs::File;

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

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 ChildStderr

Available on Unix only.
source§

impl AsFd for ChildStdin

Available on Unix only.
source§

impl AsFd for ChildStdout

Available on Unix only.
source§

impl AsFd for PidFd

Available on Linux only.
source§

impl AsFd for UnixDatagram

Available on Unix only.
source§

impl AsFd for UnixListener

Available on Unix only.
source§

impl AsFd for UnixStream

Available on Unix only.
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<T: AsFd> AsFd for &T

source§

impl<T: AsFd> AsFd for &mut T

1.64.0 · source§

impl<T: AsFd> AsFd for Box<T>

1.69.0 · source§

impl<T: AsFd> AsFd for Rc<T>

1.64.0 · source§

impl<T: AsFd> AsFd for Arc<T>

这个 impl 允许在 Arc 上实现需要 AsFd 的 traits。

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

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