Trait std::os::fd::IntoRawFd

1.4.0 · source ·
pub trait IntoRawFd {
    // Required method
    fn into_raw_fd(self) -> RawFd;
}
Expand description

一个 trait,表示消费对象并获得其原始文件描述符所有权的能力。

Required Methods§

source

fn into_raw_fd(self) -> RawFd

消费这个对象,返回原始的底层文件描述符。

此函数通常用于将底层文件描述符的所有权 ** 转移给调用者。 当以这种方式使用时,调用者是文件描述符的唯一所有者,一旦不再需要它就必须关闭它。

但是,转让所有权并不是严格要求的。 对严格转移所有权的 API 使用 Into<OwnedFd>::into 实现。

Example
use std::fs::File;
#[cfg(any(unix, target_os = "wasi"))]
use std::os::fd::{IntoRawFd, RawFd};

let f = File::open("foo.txt")?;
#[cfg(any(unix, target_os = "wasi"))]
let raw_fd: RawFd = f.into_raw_fd();
Run

Implementors§

source§

impl IntoRawFd for File

source§

impl IntoRawFd for TcpListener

source§

impl IntoRawFd for TcpStream

source§

impl IntoRawFd for UdpSocket

source§

impl IntoRawFd for ChildStderr

Available on Unix only.
source§

impl IntoRawFd for ChildStdin

Available on Unix only.
source§

impl IntoRawFd for ChildStdout

Available on Unix only.
source§

impl IntoRawFd for PidFd

Available on Linux only.
1.10.0 · source§

impl IntoRawFd for UnixDatagram

Available on Unix only.
1.10.0 · source§

impl IntoRawFd for UnixListener

Available on Unix only.
1.10.0 · source§

impl IntoRawFd for UnixStream

Available on Unix only.
1.63.0 · source§

impl IntoRawFd for OwnedFd

1.48.0 · source§

impl IntoRawFd for RawFd