pub trait AsFd {
// Required method
fn as_fd(&self) -> BorrowedFd<'_>;
}
Expand description
一个 trait 来借用来自底层对象的文件描述符。
这仅在 unix 平台上可用,并且必须导入才能调用该方法。
Windows 平台有相应的 AsHandle
和 AsSocket
的 traits 集合。
Required Methods§
sourcefn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
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 ChildStderr
Available on Unix only.
impl AsFd for ChildStdin
Available on Unix only.
impl AsFd for ChildStdout
Available on Unix only.
impl AsFd for PidFd
Available on Linux only.
impl AsFd for UnixDatagram
Available on Unix only.
impl AsFd for UnixListener
Available on Unix only.
impl AsFd for UnixStream
Available 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>
这个 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