|
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A trait to borrow the file descriptor from an underlying object."><title>AsFd in rustix::fd - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="rustix" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../rustix/index.html">rustix</a><span class="version">0.38.34</span></h2></div><h2 class="location"><a href="#">AsFd</a></h2><div class="sidebar-elems"><section><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.as_fd">as_fd</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In rustix::fd</a></h2></div></nav><div class="sidebar-resizer"></div>
|
|
|
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../../rustix/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Trait <a href="../index.html">rustix</a>::<wbr><a href="index.html">fd</a>::<wbr><a class="trait" href="#">AsFd</a><button id="copy-path" title="Copy item path to clipboard"><img src="../../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><span class="since" title="Stable since Rust version 1.63.0">1.63.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#226">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub trait AsFd {
|
|
|
// Required method
|
|
|
fn <a href="#tymethod.as_fd" class="fn">as_fd</a>(&self) -> <a class="struct" href="struct.BorrowedFd.html" title="struct rustix::fd::BorrowedFd">BorrowedFd</a><'_>;
|
|
|
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait to borrow the file descriptor from an underlying object.</p>
|
|
|
<p>This is only available on unix platforms and must be imported in order to
|
|
|
call the method. Windows platforms have a corresponding <code>AsHandle</code> and
|
|
|
<code>AsSocket</code> set of traits.</p>
|
|
|
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.as_fd" class="method"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#243">source</a><h4 class="code-header">fn <a href="#tymethod.as_fd" class="fn">as_fd</a>(&self) -> <a class="struct" href="struct.BorrowedFd.html" title="struct rustix::fd::BorrowedFd">BorrowedFd</a><'_></h4></section></summary><div class="docblock"><p>Borrows the file descriptor.</p>
|
|
|
<h5 id="example"><a href="#example">Example</a></h5>
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::fs::File;
|
|
|
|
|
|
<span class="kw">let </span><span class="kw-2">mut </span>f = File::open(<span class="string">"foo.txt"</span>)<span class="question-mark">?</span>;
|
|
|
<span class="kw">let </span>borrowed_fd: BorrowedFd<<span class="lifetime">'_</span>> = f.as_fd();</code></pre></div>
|
|
|
</div></details></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-AsFd-for-File" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#282">source</a><a href="#impl-AsFd-for-File" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/fs/struct.File.html" title="struct std::fs::File">File</a></h3></section><section id="impl-AsFd-for-Stderr" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#457">source</a><a href="#impl-AsFd-for-Stderr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/io/stdio/struct.Stderr.html" title="struct std::io::stdio::Stderr">Stderr</a></h3></section><section id="impl-AsFd-for-Stdin" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#423">source</a><a href="#impl-AsFd-for-Stdin" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/io/stdio/struct.Stdin.html" title="struct std::io::stdio::Stdin">Stdin</a></h3></section><section id="impl-AsFd-for-Stdout" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#440">source</a><a href="#impl-AsFd-for-Stdout" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/io/stdio/struct.Stdout.html" title="struct std::io::stdio::Stdout">Stdout</a></h3></section><section id="impl-AsFd-for-TcpListener" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#332">source</a><a href="#impl-AsFd-for-TcpListener" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/net/tcp/struct.TcpListener.html" title="struct std::net::tcp::TcpListener">TcpListener</a></h3></section><section id="impl-AsFd-for-TcpStream" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#306">source</a><a href="#impl-AsFd-for-TcpStream" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/net/tcp/struct.TcpStream.html" title="struct std::net::tcp::TcpStream">TcpStream</a></h3></section><section id="impl-AsFd-for-UdpSocket" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#358">source</a><a href="#impl-AsFd-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/net/udp/struct.UdpSocket.html" title="struct std::net::udp::UdpSocket">UdpSocket</a></h3></section><section id="impl-AsFd-for-PidFd" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/linux/process.rs.html#92">source</a><a href="#impl-AsFd-for-PidFd" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/os/linux/process/struct.PidFd.html" title="struct std::os::linux::process::PidFd">PidFd</a></h3></section><section id="impl-AsFd-for-UnixDatagram" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/unix/net/datagram.rs.html#1018">source</a><a href="#impl-AsFd-for-UnixDatagram" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/os/unix/net/datagram/struct.UnixDatagram.html" title="struct std::os::unix::net::datagram::UnixDatagram">UnixDatagram</a></h3></section><section id="impl-AsFd-for-UnixListener" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/unix/net/listener.rs.html#309">source</a><a href="#impl-AsFd-for-UnixListener" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/os/unix/net/listener/struct.UnixListener.html" title="struct std::os::unix::net::listener::UnixListener">UnixListener</a></h3></section><section id="impl-AsFd-for-UnixStream" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/unix/net/stream.rs.html#746">source</a><a href="#impl-AsFd-for-UnixStream" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/os/unix/net/stream/struct.UnixStream.html" title="struct std::os::unix::net::stream::UnixStream">UnixStream</a></h3></section><section id="impl-AsFd-for-ChildStderr" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/unix/process.rs.html#482">source</a><a href="#impl-AsFd-for-ChildStderr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/process/struct.ChildStderr.html" title="struct std::process::ChildStderr">ChildStderr</a></h3></section><section id="impl-AsFd-for-ChildStdin" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/unix/process.rs.html#422">source</a><a href="#impl-AsFd-for-ChildStdin" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/process/struct.ChildStdin.html" title="struct std::process::ChildStdin">ChildStdin</a></h3></section><section id="impl-AsFd-for-ChildStdout" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/unix/process.rs.html#452">source</a><a href="#impl-AsFd-for-ChildStdout" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/process/struct.ChildStdout.html" title="struct std::process::ChildStdout">ChildStdout</a></h3></section><section id="impl-AsFd-for-BorrowedFd%3C'_%3E" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#263">source</a><a href="#impl-AsFd-for-BorrowedFd%3C'_%3E" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="struct.BorrowedFd.html" title="struct rustix::fd::BorrowedFd">BorrowedFd</a><'_></h3></section><section id="impl-AsFd-for-OwnedFd" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#271">source</a><a href="#impl-AsFd-for-OwnedFd" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="struct.OwnedFd.html" title="struct rustix::fd::OwnedFd">OwnedFd</a></h3></section><section id="impl-AsFd-for-StderrLock%3C'a%3E" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#465">source</a><a href="#impl-AsFd-for-StderrLock%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/io/stdio/struct.StderrLock.html" title="struct std::io::stdio::StderrLock">StderrLock</a><'a></h3></section><section id="impl-AsFd-for-StdinLock%3C'a%3E" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#431">source</a><a href="#impl-AsFd-for-StdinLock%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/io/stdio/struct.StdinLock.html" title="struct std::io::stdio::StdinLock">StdinLock</a><'a></h3></section><section id="impl-AsFd-for-StdoutLock%3C'a%3E" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#448">source</a><a href="#impl-AsFd-for-StdoutLock%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/io/stdio/struct.StdoutLock.html" title="struct std::io::stdio::StdoutLock">StdoutLock</a><'a></h3></section><section id="impl-AsFd-for-%26T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#247">source</a><a href="#impl-AsFd-for-%26T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&T</a><div class="where">where
|
|
|
T: <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a>,</div></h3></section><section id="impl-AsFd-for-%26mut+T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#255">source</a><a href="#impl-AsFd-for-%26mut+T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&mut T</a><div class="where">where
|
|
|
T: <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a>,</div></h3></section><section id="impl-AsFd-for-Box%3CT%3E" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.64.0">1.64.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#415">source</a></span><a href="#impl-AsFd-for-Box%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><T><div class="where">where
|
|
|
T: <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a>,</div></h3></section><section id="impl-AsFd-for-Rc%3CT%3E" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.69.0">1.69.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#407">source</a></span><a href="#impl-AsFd-for-Rc%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/rc/struct.Rc.html" title="struct alloc::rc::Rc">Rc</a><T><div class="where">where
|
|
|
T: <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a>,</div></h3></section><section id="impl-AsFd-for-Arc%3CT%3E" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.64.0">1.64.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/std/os/fd/owned.rs.html#399">source</a></span><a href="#impl-AsFd-for-Arc%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc">Arc</a><T><div class="where">where
|
|
|
T: <a class="trait" href="trait.AsFd.html" title="trait rustix::fd::AsFd">AsFd</a>,</div></h3></section><div class="docblock"><p>This impl allows implementing traits that require <code>AsFd</code> on Arc.</p>
|
|
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::net::UdpSocket;
|
|
|
<span class="kw">use </span>std::sync::Arc;
|
|
|
|
|
|
<span class="kw">trait </span>MyTrait: AsFd {}
|
|
|
<span class="kw">impl </span>MyTrait <span class="kw">for </span>Arc<UdpSocket> {}
|
|
|
<span class="kw">impl </span>MyTrait <span class="kw">for </span>Box<UdpSocket> {}</code></pre></div>
|
|
|
</div></div><script src="../../trait.impl/std/os/fd/owned/trait.AsFd.js" data-ignore-extern-crates="std,alloc" async></script></section></div></main></body></html> |