mirror of
https://github.com/NotAShelf/mpvrc.git
synced 2026-04-25 10:59:59 +00:00
deploy: de38ae62916547ad097c066f94a32e9ba7790eeb
This commit is contained in:
commit
9a86359447
28502 changed files with 1261284 additions and 0 deletions
1
tokio/all.html
Normal file
1
tokio/all.html
Normal file
File diff suppressed because one or more lines are too long
154
tokio/attr.main.html
Normal file
154
tokio/attr.main.html
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
<!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="Marks async function to be executed by the selected runtime. This macro helps set up a `Runtime` without requiring the user to use Runtime or Builder directly."><title>main in tokio - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc attr"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">main</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#non-worker-async-function" title="Non-worker async function">Non-worker async function</a></li><li><a href="#multi-threaded-runtime" title="Multi-threaded runtime">Multi-threaded runtime</a></li><li><a href="#current-thread-runtime" title="Current thread runtime">Current thread runtime</a><ul><li><a href="#function-arguments" title="Function arguments:">Function arguments:</a></li><li><a href="#usage" title="Usage">Usage</a></li></ul></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate tokio</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">tokio</a></span><h1>Attribute Macro <span class="attr">main</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/tokio_macros/lib.rs.html#252">Source</a> </span></div><pre class="rust item-decl"><code>#[main]</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Marks async function to be executed by the selected runtime. This macro
|
||||
helps set up a <code>Runtime</code> without requiring the user to use
|
||||
<a href="../tokio/runtime/struct.Runtime.html">Runtime</a> or
|
||||
<a href="../tokio/runtime/struct.Builder.html">Builder</a> directly.</p>
|
||||
<p>Note: This macro is designed to be simplistic and targets applications that
|
||||
do not require a complex setup. If the provided functionality is not
|
||||
sufficient, you may be interested in using
|
||||
<a href="../tokio/runtime/struct.Builder.html">Builder</a>, which provides a more
|
||||
powerful interface.</p>
|
||||
<p>Note: This macro can be used on any function and not just the <code>main</code>
|
||||
function. Using it on a non-main function makes the function behave as if it
|
||||
was synchronous by starting a new runtime each time it is called. If the
|
||||
function is called often, it is preferable to create the runtime using the
|
||||
runtime builder so the runtime can be reused across calls.</p>
|
||||
<h2 id="non-worker-async-function"><a class="doc-anchor" href="#non-worker-async-function">§</a>Non-worker async function</h2>
|
||||
<p>Note that the async function marked with this macro does not run as a
|
||||
worker. The expectation is that other tasks are spawned by the function here.
|
||||
Awaiting on other futures from the function provided here will not
|
||||
perform as fast as those spawned as workers.</p>
|
||||
<h2 id="multi-threaded-runtime"><a class="doc-anchor" href="#multi-threaded-runtime">§</a>Multi-threaded runtime</h2>
|
||||
<p>To use the multi-threaded runtime, the macro can be configured using</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::main(flavor = <span class="string">"multi_thread"</span>, worker_threads = <span class="number">10</span>)]</span></code></pre></div>
|
||||
<p>The <code>worker_threads</code> option configures the number of worker threads, and
|
||||
defaults to the number of cpus on the system. This is the default flavor.</p>
|
||||
<p>Note: The multi-threaded runtime requires the <code>rt-multi-thread</code> feature
|
||||
flag.</p>
|
||||
<h2 id="current-thread-runtime"><a class="doc-anchor" href="#current-thread-runtime">§</a>Current thread runtime</h2>
|
||||
<p>To use the single-threaded runtime known as the <code>current_thread</code> runtime,
|
||||
the macro can be configured using</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::main(flavor = <span class="string">"current_thread"</span>)]</span></code></pre></div>
|
||||
<h3 id="function-arguments"><a class="doc-anchor" href="#function-arguments">§</a>Function arguments:</h3>
|
||||
<p>Arguments are allowed for any functions aside from <code>main</code> which is special</p>
|
||||
<h3 id="usage"><a class="doc-anchor" href="#usage">§</a>Usage</h3><h4 id="using-the-multi-thread-runtime"><a class="doc-anchor" href="#using-the-multi-thread-runtime">§</a>Using the multi-thread runtime</h4>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::main]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
})
|
||||
}</code></pre></div>
|
||||
<h4 id="using-current-thread-runtime"><a class="doc-anchor" href="#using-current-thread-runtime">§</a>Using current thread runtime</h4>
|
||||
<p>The basic scheduler is single-threaded.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::main(flavor = <span class="string">"current_thread"</span>)]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::main]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
})
|
||||
}</code></pre></div>
|
||||
<h4 id="set-number-of-worker-threads"><a class="doc-anchor" href="#set-number-of-worker-threads">§</a>Set number of worker threads</h4>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::main(worker_threads = <span class="number">2</span>)]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::main]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(<span class="number">2</span>)
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
})
|
||||
}</code></pre></div>
|
||||
<h4 id="configure-the-runtime-to-start-with-time-paused"><a class="doc-anchor" href="#configure-the-runtime-to-start-with-time-paused">§</a>Configure the runtime to start with time paused</h4>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::main(flavor = <span class="string">"current_thread"</span>, start_paused = <span class="bool-val">true</span>)]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::main]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.start_paused(<span class="bool-val">true</span>)
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
})
|
||||
}</code></pre></div>
|
||||
<p>Note that <code>start_paused</code> requires the <code>test-util</code> feature to be enabled.</p>
|
||||
<h4 id="rename-package"><a class="doc-anchor" href="#rename-package">§</a>Rename package</h4>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio <span class="kw">as </span>tokio1;
|
||||
|
||||
<span class="attr">#[tokio1::main(<span class="kw">crate </span>= <span class="string">"tokio1"</span>)]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::main]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio <span class="kw">as </span>tokio1;
|
||||
|
||||
<span class="kw">fn </span>main() {
|
||||
tokio1::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
})
|
||||
}</code></pre></div>
|
||||
<h4 id="configure-unhandled-panic-behavior"><a class="doc-anchor" href="#configure-unhandled-panic-behavior">§</a>Configure unhandled panic behavior</h4>
|
||||
<p>Available options are <code>shutdown_runtime</code> and <code>ignore</code>. For more details, see
|
||||
<a href="../tokio/runtime/struct.Builder.html#method.unhandled_panic"><code>Builder::unhandled_panic</code></a>.</p>
|
||||
<p>This option is only compatible with the <code>current_thread</code> runtime.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[cfg(tokio_unstable)]
|
||||
#[tokio::main(flavor = <span class="string">"current_thread"</span>, unhandled_panic = <span class="string">"shutdown_runtime"</span>)]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let _ </span>= tokio::spawn(<span class="kw">async </span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"This panic will shutdown the runtime."</span>);
|
||||
}).<span class="kw">await</span>;
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::main]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[cfg(tokio_unstable)]
|
||||
</span><span class="kw">fn </span>main() {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.unhandled_panic(UnhandledPanic::ShutdownRuntime)
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="kw">let _ </span>= tokio::spawn(<span class="kw">async </span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"This panic will shutdown the runtime."</span>);
|
||||
}).<span class="kw">await</span>;
|
||||
})
|
||||
}</code></pre></div>
|
||||
<p><strong>Note</strong>: This option depends on Tokio’s <a href="../tokio/index.html#unstable-features">unstable API</a>. See <a href="../tokio/index.html#unstable-features">the
|
||||
documentation on unstable features</a> for details on how to enable
|
||||
Tokio’s unstable features.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
138
tokio/attr.test.html
Normal file
138
tokio/attr.test.html
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
<!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="Marks async function to be executed by runtime, suitable to test environment. This macro helps set up a `Runtime` without requiring the user to use Runtime or Builder directly."><title>test in tokio - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc attr"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">test</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#multi-threaded-runtime" title="Multi-threaded runtime">Multi-threaded runtime</a></li><li><a href="#current-thread-runtime" title="Current thread runtime">Current thread runtime</a><ul><li><a href="#usage" title="Usage">Usage</a></li></ul></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate tokio</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">tokio</a></span><h1>Attribute Macro <span class="attr">test</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/tokio_macros/lib.rs.html#520">Source</a> </span></div><pre class="rust item-decl"><code>#[test]</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Marks async function to be executed by runtime, suitable to test environment.
|
||||
This macro helps set up a <code>Runtime</code> without requiring the user to use
|
||||
<a href="../tokio/runtime/struct.Runtime.html">Runtime</a> or
|
||||
<a href="../tokio/runtime/struct.Builder.html">Builder</a> directly.</p>
|
||||
<p>Note: This macro is designed to be simplistic and targets applications that
|
||||
do not require a complex setup. If the provided functionality is not
|
||||
sufficient, you may be interested in using
|
||||
<a href="../tokio/runtime/struct.Builder.html">Builder</a>, which provides a more
|
||||
powerful interface.</p>
|
||||
<h2 id="multi-threaded-runtime"><a class="doc-anchor" href="#multi-threaded-runtime">§</a>Multi-threaded runtime</h2>
|
||||
<p>To use the multi-threaded runtime, the macro can be configured using</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::test(flavor = <span class="string">"multi_thread"</span>, worker_threads = <span class="number">1</span>)]
|
||||
</span><span class="kw">async fn </span>my_test() {
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
}</code></pre></div>
|
||||
<p>The <code>worker_threads</code> option configures the number of worker threads, and
|
||||
defaults to the number of cpus on the system.</p>
|
||||
<p>Note: The multi-threaded runtime requires the <code>rt-multi-thread</code> feature
|
||||
flag.</p>
|
||||
<h2 id="current-thread-runtime"><a class="doc-anchor" href="#current-thread-runtime">§</a>Current thread runtime</h2>
|
||||
<p>The default test runtime is single-threaded. Each test gets a
|
||||
separate current-thread runtime.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::test]
|
||||
</span><span class="kw">async fn </span>my_test() {
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
}</code></pre></div>
|
||||
<h3 id="usage"><a class="doc-anchor" href="#usage">§</a>Usage</h3><h4 id="using-the-multi-thread-runtime"><a class="doc-anchor" href="#using-the-multi-thread-runtime">§</a>Using the multi-thread runtime</h4>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::test(flavor = <span class="string">"multi_thread"</span>)]
|
||||
</span><span class="kw">async fn </span>my_test() {
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::test]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[test]
|
||||
</span><span class="kw">fn </span>my_test() {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
})
|
||||
}</code></pre></div>
|
||||
<h4 id="using-current-thread-runtime"><a class="doc-anchor" href="#using-current-thread-runtime">§</a>Using current thread runtime</h4>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::test]
|
||||
</span><span class="kw">async fn </span>my_test() {
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::test]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[test]
|
||||
</span><span class="kw">fn </span>my_test() {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
})
|
||||
}</code></pre></div>
|
||||
<h4 id="set-number-of-worker-threads"><a class="doc-anchor" href="#set-number-of-worker-threads">§</a>Set number of worker threads</h4>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::test(flavor = <span class="string">"multi_thread"</span>, worker_threads = <span class="number">2</span>)]
|
||||
</span><span class="kw">async fn </span>my_test() {
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::test]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[test]
|
||||
</span><span class="kw">fn </span>my_test() {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(<span class="number">2</span>)
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
})
|
||||
}</code></pre></div>
|
||||
<h4 id="configure-the-runtime-to-start-with-time-paused"><a class="doc-anchor" href="#configure-the-runtime-to-start-with-time-paused">§</a>Configure the runtime to start with time paused</h4>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::test(start_paused = <span class="bool-val">true</span>)]
|
||||
</span><span class="kw">async fn </span>my_test() {
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::test]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[test]
|
||||
</span><span class="kw">fn </span>my_test() {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.start_paused(<span class="bool-val">true</span>)
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
})
|
||||
}</code></pre></div>
|
||||
<p>Note that <code>start_paused</code> requires the <code>test-util</code> feature to be enabled.</p>
|
||||
<h4 id="rename-package"><a class="doc-anchor" href="#rename-package">§</a>Rename package</h4>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio <span class="kw">as </span>tokio1;
|
||||
|
||||
<span class="attr">#[tokio1::test(<span class="kw">crate </span>= <span class="string">"tokio1"</span>)]
|
||||
</span><span class="kw">async fn </span>my_test() {
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
}</code></pre></div>
|
||||
<h4 id="configure-unhandled-panic-behavior"><a class="doc-anchor" href="#configure-unhandled-panic-behavior">§</a>Configure unhandled panic behavior</h4>
|
||||
<p>Available options are <code>shutdown_runtime</code> and <code>ignore</code>. For more details, see
|
||||
<a href="../tokio/runtime/struct.Builder.html#method.unhandled_panic"><code>Builder::unhandled_panic</code></a>.</p>
|
||||
<p>This option is only compatible with the <code>current_thread</code> runtime.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[cfg(tokio_unstable)]
|
||||
#[tokio::test(flavor = <span class="string">"current_thread"</span>, unhandled_panic = <span class="string">"shutdown_runtime"</span>)]
|
||||
</span><span class="kw">async fn </span>my_test() {
|
||||
<span class="kw">let _ </span>= tokio::spawn(<span class="kw">async </span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"This panic will shutdown the runtime."</span>);
|
||||
}).<span class="kw">await</span>;
|
||||
}</code></pre></div>
|
||||
<p>Equivalent code not using <code>#[tokio::test]</code></p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[cfg(tokio_unstable)]
|
||||
#[test]
|
||||
</span><span class="kw">fn </span>my_test() {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.unhandled_panic(UnhandledPanic::ShutdownRuntime)
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(<span class="kw">async </span>{
|
||||
<span class="kw">let _ </span>= tokio::spawn(<span class="kw">async </span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"This panic will shutdown the runtime."</span>);
|
||||
}).<span class="kw">await</span>;
|
||||
})
|
||||
}</code></pre></div>
|
||||
<p><strong>Note</strong>: This option depends on Tokio’s <a href="../tokio/index.html#unstable-features">unstable API</a>. See <a href="../tokio/index.html#unstable-features">the
|
||||
documentation on unstable features</a> for details on how to enable
|
||||
Tokio’s unstable features.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
11
tokio/fs/canonicalize/fn.canonicalize.html
Normal file
11
tokio/fs/canonicalize/fn.canonicalize.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.canonicalize.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.canonicalize.html">../../../tokio/fs/fn.canonicalize.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.canonicalize.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/copy/fn.copy.html
Normal file
11
tokio/fs/copy/fn.copy.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.copy.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.copy.html">../../../tokio/fs/fn.copy.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.copy.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/create_dir/fn.create_dir.html
Normal file
11
tokio/fs/create_dir/fn.create_dir.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.create_dir.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.create_dir.html">../../../tokio/fs/fn.create_dir.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.create_dir.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/create_dir_all/fn.create_dir_all.html
Normal file
11
tokio/fs/create_dir_all/fn.create_dir_all.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.create_dir_all.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.create_dir_all.html">../../../tokio/fs/fn.create_dir_all.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.create_dir_all.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/dir_builder/struct.DirBuilder.html
Normal file
11
tokio/fs/dir_builder/struct.DirBuilder.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/struct.DirBuilder.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/struct.DirBuilder.html">../../../tokio/fs/struct.DirBuilder.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/struct.DirBuilder.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/file/struct.File.html
Normal file
11
tokio/fs/file/struct.File.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/struct.File.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/struct.File.html">../../../tokio/fs/struct.File.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/struct.File.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
29
tokio/fs/fn.canonicalize.html
Normal file
29
tokio/fs/fn.canonicalize.html
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<!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="Returns the canonical, absolute form of a path with all intermediate components normalized and symbolic links resolved."><title>canonicalize in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">canonicalize</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#platform-specific-behavior" title="Platform-specific behavior">Platform-specific behavior</a></li><li><a href="#errors" title="Errors">Errors</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">canonicalize</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/canonicalize.rs.html#46-49">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn canonicalize(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Returns the canonical, absolute form of a path with all intermediate
|
||||
components normalized and symbolic links resolved.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.canonicalize.html" title="fn std::fs::canonicalize"><code>std::fs::canonicalize</code></a>.</p>
|
||||
<h2 id="platform-specific-behavior"><a class="doc-anchor" href="#platform-specific-behavior">§</a>Platform-specific behavior</h2>
|
||||
<p>This function currently corresponds to the <code>realpath</code> function on Unix
|
||||
and the <code>CreateFile</code> and <code>GetFinalPathNameByHandle</code> functions on Windows.
|
||||
Note that, this <a href="https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior">may change in the future</a>.</p>
|
||||
<p>On Windows, this converts the path to use <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath">extended length path</a>
|
||||
syntax, which allows your program to use longer path names, but means you
|
||||
can only join backslash-delimited paths to it, and it may be incompatible
|
||||
with other applications (if passed to the application on the command-line,
|
||||
or written to a file another application may read).</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<p>This function will return an error in the following situations, but is not
|
||||
limited to just these cases:</p>
|
||||
<ul>
|
||||
<li><code>path</code> does not exist.</li>
|
||||
<li>A non-final component in path is not a directory.</li>
|
||||
</ul>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
<span class="kw">use </span>std::io;
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||||
<span class="kw">let </span>path = fs::canonicalize(<span class="string">"../a/../foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
12
tokio/fs/fn.copy.html
Normal file
12
tokio/fs/fn.copy.html
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<!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="Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file. This function will overwrite the contents of to."><title>copy in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">copy</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">copy</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/copy.rs.html#21-25">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn copy(
|
||||
from: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>,
|
||||
to: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>,
|
||||
) -> <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u64.html">u64</a>, <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Copies the contents of one file to another. This function will also copy the permission bits
|
||||
of the original file to the destination file.
|
||||
This function will overwrite the contents of to.</p>
|
||||
<p>This is the async equivalent of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.copy.html" title="fn std::fs::copy"><code>std::fs::copy</code></a>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
fs::copy(<span class="string">"foo.txt"</span>, <span class="string">"bar.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
29
tokio/fs/fn.create_dir.html
Normal file
29
tokio/fs/fn.create_dir.html
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<!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="Creates a new, empty directory at the provided path."><title>create_dir in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">create_<wbr>dir</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#platform-specific-behavior" title="Platform-specific behavior">Platform-specific behavior</a></li><li><a href="#errors" title="Errors">Errors</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">create_dir</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/create_dir.rs.html#47-50">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn create_dir(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates a new, empty directory at the provided path.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.create_dir.html" title="fn std::fs::create_dir"><code>std::fs::create_dir</code></a>.</p>
|
||||
<h2 id="platform-specific-behavior"><a class="doc-anchor" href="#platform-specific-behavior">§</a>Platform-specific behavior</h2>
|
||||
<p>This function currently corresponds to the <code>mkdir</code> function on Unix
|
||||
and the <code>CreateDirectory</code> function on Windows.
|
||||
Note that, this <a href="https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior">may change in the future</a>.</p>
|
||||
<p><strong>NOTE</strong>: If a parent of the given path doesn’t exist, this function will
|
||||
return an error. To create a directory and all its missing parents at the
|
||||
same time, use the <a href="fn.create_dir_all.html" title="fn tokio::fs::create_dir_all"><code>create_dir_all</code></a> function.</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<p>This function will return an error in the following situations, but is not
|
||||
limited to just these cases:</p>
|
||||
<ul>
|
||||
<li>User lacks permissions to create directory at <code>path</code>.</li>
|
||||
<li>A parent of the given path doesn’t exist. (To create a directory and all
|
||||
its missing parents at the same time, use the <a href="fn.create_dir_all.html" title="fn tokio::fs::create_dir_all"><code>create_dir_all</code></a>
|
||||
function.)</li>
|
||||
<li><code>path</code> already exists.</li>
|
||||
</ul>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
<span class="kw">use </span>std::io;
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||||
fs::create_dir(<span class="string">"/some/dir"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
30
tokio/fs/fn.create_dir_all.html
Normal file
30
tokio/fs/fn.create_dir_all.html
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<!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="Recursively creates a directory and all of its parent components if they are missing."><title>create_dir_all in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">create_<wbr>dir_<wbr>all</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#platform-specific-behavior" title="Platform-specific behavior">Platform-specific behavior</a></li><li><a href="#errors" title="Errors">Errors</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">create_dir_all</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/create_dir_all.rs.html#48-51">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn create_dir_all(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Recursively creates a directory and all of its parent components if they
|
||||
are missing.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.create_dir_all.html" title="fn std::fs::create_dir_all"><code>std::fs::create_dir_all</code></a>.</p>
|
||||
<h2 id="platform-specific-behavior"><a class="doc-anchor" href="#platform-specific-behavior">§</a>Platform-specific behavior</h2>
|
||||
<p>This function currently corresponds to the <code>mkdir</code> function on Unix
|
||||
and the <code>CreateDirectory</code> function on Windows.
|
||||
Note that, this <a href="https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior">may change in the future</a>.</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<p>This function will return an error in the following situations, but is not
|
||||
limited to just these cases:</p>
|
||||
<ul>
|
||||
<li>If any directory in the path specified by <code>path</code> does not already exist
|
||||
and it could not be created otherwise. The specific error conditions for
|
||||
when a directory is being created (after it is determined to not exist) are
|
||||
outlined by <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.create_dir.html" title="fn std::fs::create_dir"><code>fs::create_dir</code></a>.</li>
|
||||
</ul>
|
||||
<p>Notable exception is made for situations where any of the directories
|
||||
specified in the <code>path</code> could not be created as it was being created concurrently.
|
||||
Such cases are considered to be successful. That is, calling <code>create_dir_all</code>
|
||||
concurrently from multiple threads or processes is guaranteed not to fail
|
||||
due to a race condition with itself.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> std::io::Result<()> {
|
||||
fs::create_dir_all(<span class="string">"/some/dir"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
26
tokio/fs/fn.hard_link.html
Normal file
26
tokio/fs/fn.hard_link.html
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<!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="Creates a new hard link on the filesystem."><title>hard_link in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">hard_<wbr>link</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#platform-specific-behavior" title="Platform-specific behavior">Platform-specific behavior</a></li><li><a href="#errors" title="Errors">Errors</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">hard_link</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/hard_link.rs.html#39-44">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn hard_link(
|
||||
src: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>,
|
||||
dst: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>,
|
||||
) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates a new hard link on the filesystem.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.hard_link.html" title="fn std::fs::hard_link"><code>std::fs::hard_link</code></a>.</p>
|
||||
<p>The <code>dst</code> path will be a link pointing to the <code>src</code> path. Note that systems
|
||||
often require these two paths to both be located on the same filesystem.</p>
|
||||
<h2 id="platform-specific-behavior"><a class="doc-anchor" href="#platform-specific-behavior">§</a>Platform-specific behavior</h2>
|
||||
<p>This function currently corresponds to the <code>link</code> function on Unix
|
||||
and the <code>CreateHardLink</code> function on Windows.
|
||||
Note that, this <a href="https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior">may change in the future</a>.</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<p>This function will return an error in the following situations, but is not
|
||||
limited to just these cases:</p>
|
||||
<ul>
|
||||
<li>The <code>src</code> path is not a file or doesn’t exist.</li>
|
||||
</ul>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> std::io::Result<()> {
|
||||
fs::hard_link(<span class="string">"a.txt"</span>, <span class="string">"b.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>; <span class="comment">// Hard link a.txt to b.txt
|
||||
</span><span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
26
tokio/fs/fn.metadata.html
Normal file
26
tokio/fs/fn.metadata.html
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<!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="Given a path, queries the file system to get information about a file, directory, etc."><title>metadata in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">metadata</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#platform-specific-behavior" title="Platform-specific behavior">Platform-specific behavior</a></li><li><a href="#errors" title="Errors">Errors</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">metadata</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/metadata.rs.html#43-46">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn metadata(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/fs/struct.Metadata.html" title="struct std::fs::Metadata">Metadata</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Given a path, queries the file system to get information about a file,
|
||||
directory, etc.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.metadata.html" title="fn std::fs::metadata"><code>std::fs::metadata</code></a>.</p>
|
||||
<p>This function will traverse symbolic links to query information about the
|
||||
destination file.</p>
|
||||
<h2 id="platform-specific-behavior"><a class="doc-anchor" href="#platform-specific-behavior">§</a>Platform-specific behavior</h2>
|
||||
<p>This function currently corresponds to the <code>stat</code> function on Unix and the
|
||||
<code>GetFileAttributesEx</code> function on Windows. Note that, this <a href="https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior">may change in
|
||||
the future</a>.</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<p>This function will return an error in the following situations, but is not
|
||||
limited to just these cases:</p>
|
||||
<ul>
|
||||
<li>The user lacks permissions to perform <code>metadata</code> call on <code>path</code>.</li>
|
||||
<li><code>path</code> does not exist.</li>
|
||||
</ul>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> std::io::Result<()> {
|
||||
<span class="kw">let </span>attr = fs::metadata(<span class="string">"/some/file/path.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="comment">// inspect attr ...
|
||||
</span><span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
24
tokio/fs/fn.read.html
Normal file
24
tokio/fs/fn.read.html
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<!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="Reads the entire contents of a file into a bytes vector."><title>read in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">read</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#errors" title="Errors">Errors</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">read</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/read.rs.html#46-49">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn read(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u8.html">u8</a>>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Reads the entire contents of a file into a bytes vector.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.read.html" title="fn std::fs::read"><code>std::fs::read</code></a>.</p>
|
||||
<p>This is a convenience function for using <a href="struct.File.html#method.open" title="associated function tokio::fs::File::open"><code>File::open</code></a> and <a href="../io/trait.AsyncReadExt.html#method.read_to_end" title="method tokio::io::AsyncReadExt::read_to_end"><code>read_to_end</code></a>
|
||||
with fewer imports and without an intermediate variable. It pre-allocates a
|
||||
buffer based on the file size when available, so it is generally faster than
|
||||
reading into a vector created with <code>Vec::new()</code>.</p>
|
||||
<p>This operation is implemented by running the equivalent blocking operation
|
||||
on a separate thread pool using <a href="../task/fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a>.</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<p>This function will return an error if <code>path</code> does not already exist.
|
||||
Other errors may also be returned according to <a href="struct.OpenOptions.html#method.open" title="method tokio::fs::OpenOptions::open"><code>OpenOptions::open</code></a>.</p>
|
||||
<p>It will also return an error if it encounters while reading an error
|
||||
of a kind other than <a href="https://doc.rust-lang.org/1.84.1/std/io/error/enum.ErrorKind.html#variant.Interrupted" title="variant std::io::error::ErrorKind::Interrupted"><code>ErrorKind::Interrupted</code></a>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
<span class="kw">use </span>std::net::SocketAddr;
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> <span class="prelude-ty">Result</span><(), Box<<span class="kw">dyn </span>std::error::Error + <span class="lifetime">'static</span>>> {
|
||||
<span class="kw">let </span>contents = fs::read(<span class="string">"address.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>foo: SocketAddr = String::from_utf8_lossy(<span class="kw-2">&</span>contents).parse()<span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
5
tokio/fs/fn.read_dir.html
Normal file
5
tokio/fs/fn.read_dir.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<!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="Returns a stream over the entries within a directory."><title>read_dir in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">read_dir</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/read_dir.rs.html#32-42">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn read_dir(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="struct.ReadDir.html" title="struct tokio::fs::ReadDir">ReadDir</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Returns a stream over the entries within a directory.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.read_dir.html" title="fn std::fs::read_dir"><code>std::fs::read_dir</code></a>.</p>
|
||||
<p>This operation is implemented by running the equivalent blocking
|
||||
operation on a separate thread pool using <a href="../task/fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a>.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
3
tokio/fs/fn.read_link.html
Normal file
3
tokio/fs/fn.read_link.html
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<!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="Reads a symbolic link, returning the file that the link points to."><title>read_link in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">read_link</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/read_link.rs.html#9-12">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn read_link(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Reads a symbolic link, returning the file that the link points to.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.read_link.html" title="fn std::fs::read_link"><code>std::fs::read_link</code></a>.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
11
tokio/fs/fn.read_to_string.html
Normal file
11
tokio/fs/fn.read_to_string.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!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="Creates a future which will open a file for reading and read the entire contents into a string and return said string."><title>read_to_string in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">read_<wbr>to_<wbr>string</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">read_to_string</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/read_to_string.rs.html#27-30">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn read_to_string(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates a future which will open a file for reading and read the entire
|
||||
contents into a string and return said string.</p>
|
||||
<p>This is the async equivalent of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.read_to_string.html" title="fn std::fs::read_to_string"><code>std::fs::read_to_string</code></a>.</p>
|
||||
<p>This operation is implemented by running the equivalent blocking operation
|
||||
on a separate thread pool using <a href="../task/fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
<span class="kw">let </span>contents = fs::read_to_string(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">println!</span>(<span class="string">"foo.txt contains {} bytes"</span>, contents.len());</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
3
tokio/fs/fn.remove_dir.html
Normal file
3
tokio/fs/fn.remove_dir.html
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<!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="Removes an existing, empty directory."><title>remove_dir in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">remove_dir</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/remove_dir.rs.html#9-12">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn remove_dir(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Removes an existing, empty directory.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.remove_dir.html" title="fn std::fs::remove_dir"><code>std::fs::remove_dir</code></a>.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
3
tokio/fs/fn.remove_dir_all.html
Normal file
3
tokio/fs/fn.remove_dir_all.html
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<!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="Removes a directory at this path, after removing all its contents. Use carefully!"><title>remove_dir_all in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">remove_dir_all</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/remove_dir_all.rs.html#11-14">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn remove_dir_all(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Removes a directory at this path, after removing all its contents. Use carefully!</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.remove_dir_all.html" title="fn std::fs::remove_dir_all"><code>std::fs::remove_dir_all</code></a></p>
|
||||
</div></details></section></div></main></body></html>
|
||||
6
tokio/fs/fn.remove_file.html
Normal file
6
tokio/fs/fn.remove_file.html
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<!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="Removes a file from the filesystem."><title>remove_file in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">remove_file</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/remove_file.rs.html#13-16">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn remove_file(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Removes a file from the filesystem.</p>
|
||||
<p>Note that there is no guarantee that the file is immediately deleted (e.g.
|
||||
depending on platform, other open file descriptors may prevent immediate
|
||||
removal).</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.remove_file.html" title="fn std::fs::remove_file"><code>std::fs::remove_file</code></a>.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
5
tokio/fs/fn.rename.html
Normal file
5
tokio/fs/fn.rename.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<!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="Renames a file or directory to a new name, replacing the original file if `to` already exists."><title>rename in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">rename</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/rename.rs.html#12-17">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn rename(from: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>, to: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Renames a file or directory to a new name, replacing the original file if
|
||||
<code>to</code> already exists.</p>
|
||||
<p>This will not work if the new name is on a different mount point.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.rename.html" title="fn std::fs::rename"><code>std::fs::rename</code></a>.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
6
tokio/fs/fn.set_permissions.html
Normal file
6
tokio/fs/fn.set_permissions.html
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<!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="Changes the permissions found on a file or a directory."><title>set_permissions in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">set_permissions</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/set_permissions.rs.html#12-15">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn set_permissions(
|
||||
path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>,
|
||||
perm: <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/fs/struct.Permissions.html" title="struct std::fs::Permissions">Permissions</a>,
|
||||
) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Changes the permissions found on a file or a directory.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.set_permissions.html" title="fn std::fs::set_permissions"><code>std::fs::set_permissions</code></a></p>
|
||||
</div></details></section></div></main></body></html>
|
||||
4
tokio/fs/fn.symlink.html
Normal file
4
tokio/fs/fn.symlink.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<!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="Creates a new symbolic link on the filesystem."><title>symlink in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">symlink</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/symlink.rs.html#11-16">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn symlink(src: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>, dst: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates a new symbolic link on the filesystem.</p>
|
||||
<p>The <code>dst</code> path will be a symbolic link pointing to the <code>src</code> path.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/os/unix/fs/fn.symlink.html" title="fn std::os::unix::fs::symlink"><code>std::os::unix::fs::symlink</code></a>.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
3
tokio/fs/fn.symlink_metadata.html
Normal file
3
tokio/fs/fn.symlink_metadata.html
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<!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="Queries the file system metadata for a path."><title>symlink_metadata in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">symlink_metadata</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/symlink_metadata.rs.html#12-15">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn symlink_metadata(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/fs/struct.Metadata.html" title="struct std::fs::Metadata">Metadata</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Queries the file system metadata for a path.</p>
|
||||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.symlink_metadata.html" title="fn std::fs::symlink_metadata"><code>std::fs::symlink_metadata</code></a></p>
|
||||
</div></details></section></div></main></body></html>
|
||||
9
tokio/fs/fn.try_exists.html
Normal file
9
tokio/fs/fn.try_exists.html
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<!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="Returns `Ok(true)` if the path points at an existing entity."><title>try_exists in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">try_<wbr>exists</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">try_exists</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/try_exists.rs.html#25-28">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn try_exists(path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Returns <code>Ok(true)</code> if the path points at an existing entity.</p>
|
||||
<p>This function will traverse symbolic links to query information about the
|
||||
destination file. In case of broken symbolic links this will return <code>Ok(false)</code>.</p>
|
||||
<p>This is the async equivalent of <a href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html#method.try_exists" title="method std::path::Path::try_exists"><code>std::path::Path::try_exists</code></a>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
fs::try_exists(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
13
tokio/fs/fn.write.html
Normal file
13
tokio/fs/fn.write.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!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="Creates a future that will open a file for writing and write the entire contents of `contents` to it."><title>write in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">write</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Function <span class="fn">write</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/write.rs.html#26-31">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn write(
|
||||
path: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>,
|
||||
contents: impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u8.html">u8</a>]>,
|
||||
) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates a future that will open a file for writing and write the entire
|
||||
contents of <code>contents</code> to it.</p>
|
||||
<p>This is the async equivalent of <a href="https://doc.rust-lang.org/1.84.1/std/fs/fn.write.html" title="fn std::fs::write"><code>std::fs::write</code></a>.</p>
|
||||
<p>This operation is implemented by running the equivalent blocking operation
|
||||
on a separate thread pool using <a href="../task/fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
fs::write(<span class="string">"foo.txt"</span>, <span class="string">b"Hello world!"</span>).<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
11
tokio/fs/hard_link/fn.hard_link.html
Normal file
11
tokio/fs/hard_link/fn.hard_link.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.hard_link.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.hard_link.html">../../../tokio/fs/fn.hard_link.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.hard_link.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
156
tokio/fs/index.html
Normal file
156
tokio/fs/index.html
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
<!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="Asynchronous file utilities."><title>tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module fs</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#usage" title="Usage">Usage</a><ul><li><a href="#using-file" title="Using `File`">Using <code>File</code></a></li><li><a href="#tuning-your-file-io" title="Tuning your file IO">Tuning your file IO</a></li></ul></li></ul><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate tokio</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a></span><h1>Module <span>fs</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/mod.rs.html#1-317">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Asynchronous file utilities.</p>
|
||||
<p>This module contains utility methods for working with the file system
|
||||
asynchronously. This includes reading/writing to files, and working with
|
||||
directories.</p>
|
||||
<p>Be aware that most operating systems do not provide asynchronous file system
|
||||
APIs. Because of that, Tokio will use ordinary blocking file operations
|
||||
behind the scenes. This is done using the <a href="../task/fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a> threadpool to
|
||||
run them in the background.</p>
|
||||
<p>The <code>tokio::fs</code> module should only be used for ordinary files. Trying to use
|
||||
it with e.g., a named pipe on Linux can result in surprising behavior,
|
||||
such as hangs during runtime shutdown. For special files, you should use a
|
||||
dedicated type such as <a href="../net/unix/pipe/index.html" title="mod tokio::net::unix::pipe"><code>tokio::net::unix::pipe</code></a> or <a href="../io/unix/struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd"><code>AsyncFd</code></a> instead.</p>
|
||||
<p>Currently, Tokio will always use <a href="../task/fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a> on all platforms, but it
|
||||
may be changed to use asynchronous file system APIs such as io_uring in the
|
||||
future.</p>
|
||||
<h2 id="usage"><a class="doc-anchor" href="#usage">§</a>Usage</h2>
|
||||
<p>The easiest way to use this module is to use the utility functions that
|
||||
operate on entire files:</p>
|
||||
<ul>
|
||||
<li><a href="fn.read.html" title="fn tokio::fs::read"><code>tokio::fs::read</code></a></li>
|
||||
<li><a href="fn.read_to_string.html" title="fn tokio::fs::read_to_string"><code>tokio::fs::read_to_string</code></a></li>
|
||||
<li><a href="fn.write.html" title="fn tokio::fs::write"><code>tokio::fs::write</code></a></li>
|
||||
</ul>
|
||||
<p>The two <code>read</code> functions reads the entire file and returns its contents.
|
||||
The <code>write</code> function takes the contents of the file and writes those
|
||||
contents to the file. It overwrites the existing file, if any.</p>
|
||||
<p>For example, to read the file:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>contents = tokio::fs::read_to_string(<span class="string">"my_file.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="macro">println!</span>(<span class="string">"File has {} lines."</span>, contents.lines().count());</code></pre></div>
|
||||
<p>To overwrite the file:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>contents = <span class="string">"First line.\nSecond line.\nThird line.\n"</span>;
|
||||
|
||||
tokio::fs::write(<span class="string">"my_file.txt"</span>, contents.as_bytes()).<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
|
||||
<h3 id="using-file"><a class="doc-anchor" href="#using-file">§</a>Using <code>File</code></h3>
|
||||
<p>The main type for interacting with files is <a href="struct.File.html" title="struct tokio::fs::File"><code>File</code></a>. It can be used to read
|
||||
from and write to a given file. This is done using the <a href="../io/trait.AsyncRead.html" title="trait tokio::io::AsyncRead"><code>AsyncRead</code></a> and
|
||||
<a href="../io/trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite"><code>AsyncWrite</code></a> traits. This type is generally used when you want to do
|
||||
something more complex than just reading or writing the entire contents in
|
||||
one go.</p>
|
||||
<p><strong>Note:</strong> It is important to use <a href="../io/trait.AsyncWriteExt.html#method.flush" title="method tokio::io::AsyncWriteExt::flush"><code>flush</code></a> when writing to a Tokio
|
||||
<a href="struct.File.html" title="struct tokio::fs::File"><code>File</code></a>. This is because calls to <code>write</code> will return before the write has
|
||||
finished, and <a href="../io/trait.AsyncWriteExt.html#method.flush" title="method tokio::io::AsyncWriteExt::flush"><code>flush</code></a> will wait for the write to finish. (The write will
|
||||
happen even if you don’t flush; it will just happen later.) This is
|
||||
different from <a href="https://doc.rust-lang.org/1.84.1/std/fs/struct.File.html" title="struct std::fs::File"><code>std::fs::File</code></a>, and is due to the fact that <code>File</code> uses
|
||||
<code>spawn_blocking</code> behind the scenes.</p>
|
||||
<p>For example, to count the number of lines in a file without loading the
|
||||
entire file into memory:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::File;
|
||||
<span class="kw">use </span>tokio::io::AsyncReadExt;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>file = File::open(<span class="string">"my_file.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>chunk = <span class="macro">vec!</span>[<span class="number">0</span>; <span class="number">4096</span>];
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>number_of_lines = <span class="number">0</span>;
|
||||
<span class="kw">loop </span>{
|
||||
<span class="kw">let </span>len = file.read(<span class="kw-2">&mut </span>chunk).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">if </span>len == <span class="number">0 </span>{
|
||||
<span class="comment">// Length of zero means end of file.
|
||||
</span><span class="kw">break</span>;
|
||||
}
|
||||
<span class="kw">for </span><span class="kw-2">&</span>b <span class="kw">in </span><span class="kw-2">&</span>chunk[..len] {
|
||||
<span class="kw">if </span>b == <span class="string">b'\n' </span>{
|
||||
number_of_lines += <span class="number">1</span>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="macro">println!</span>(<span class="string">"File has {} lines."</span>, number_of_lines);</code></pre></div>
|
||||
<p>For example, to write a file line-by-line:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::File;
|
||||
<span class="kw">use </span>tokio::io::AsyncWriteExt;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>file = File::create(<span class="string">"my_file.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
file.write_all(<span class="string">b"First line.\n"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
file.write_all(<span class="string">b"Second line.\n"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
file.write_all(<span class="string">b"Third line.\n"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// Remember to call `flush` after writing!
|
||||
</span>file.flush().<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
|
||||
<h3 id="tuning-your-file-io"><a class="doc-anchor" href="#tuning-your-file-io">§</a>Tuning your file IO</h3>
|
||||
<p>Tokio’s file uses <a href="../task/fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a> behind the scenes, and this has serious
|
||||
performance consequences. To get good performance with file IO on Tokio, it
|
||||
is recommended to batch your operations into as few <code>spawn_blocking</code> calls
|
||||
as possible.</p>
|
||||
<p>One example of this difference can be seen by comparing the two reading
|
||||
examples above. The first example uses <a href="fn.read.html" title="fn tokio::fs::read"><code>tokio::fs::read</code></a>, which reads the
|
||||
entire file in a single <code>spawn_blocking</code> call, and then returns it. The
|
||||
second example will read the file in chunks using many <code>spawn_blocking</code>
|
||||
calls. This means that the second example will most likely be more expensive
|
||||
for large files. (Of course, using chunks may be necessary for very large
|
||||
files that don’t fit in memory.)</p>
|
||||
<p>The following examples will show some strategies for this:</p>
|
||||
<p>When creating a file, write the data to a <code>String</code> or <code>Vec<u8></code> and then
|
||||
write the entire file in a single <code>spawn_blocking</code> call with
|
||||
<code>tokio::fs::write</code>.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>contents = String::new();
|
||||
|
||||
contents.push_str(<span class="string">"First line.\n"</span>);
|
||||
contents.push_str(<span class="string">"Second line.\n"</span>);
|
||||
contents.push_str(<span class="string">"Third line.\n"</span>);
|
||||
|
||||
tokio::fs::write(<span class="string">"my_file.txt"</span>, contents.as_bytes()).<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
|
||||
<p>Use <a href="../io/struct.BufReader.html" title="struct tokio::io::BufReader"><code>BufReader</code></a> and <a href="../io/struct.BufWriter.html" title="struct tokio::io::BufWriter"><code>BufWriter</code></a> to buffer many small reads or writes
|
||||
into a few large ones. This example will most likely only perform one
|
||||
<code>spawn_blocking</code> call.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::File;
|
||||
<span class="kw">use </span>tokio::io::{AsyncWriteExt, BufWriter};
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>file = BufWriter::new(File::create(<span class="string">"my_file.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>);
|
||||
|
||||
file.write_all(<span class="string">b"First line.\n"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
file.write_all(<span class="string">b"Second line.\n"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
file.write_all(<span class="string">b"Third line.\n"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// Due to the BufWriter, the actual write and spawn_blocking
|
||||
// call happens when you flush.
|
||||
</span>file.flush().<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
|
||||
<p>Manually use <a href="https://doc.rust-lang.org/1.84.1/std/fs/index.html" title="mod std::fs"><code>std::fs</code></a> inside <a href="../task/fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a>.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::fs::File;
|
||||
<span class="kw">use </span>std::io::{<span class="self">self</span>, Write};
|
||||
<span class="kw">use </span>tokio::task::spawn_blocking;
|
||||
|
||||
spawn_blocking(<span class="kw">move </span>|| {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>file = File::create(<span class="string">"my_file.txt"</span>)<span class="question-mark">?</span>;
|
||||
|
||||
file.write_all(<span class="string">b"First line.\n"</span>)<span class="question-mark">?</span>;
|
||||
file.write_all(<span class="string">b"Second line.\n"</span>)<span class="question-mark">?</span>;
|
||||
file.write_all(<span class="string">b"Third line.\n"</span>)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// Unlike Tokio's file, the std::fs file does
|
||||
// not need flush.
|
||||
|
||||
</span>io::Result::Ok(())
|
||||
}).<span class="kw">await</span>.unwrap()<span class="question-mark">?</span>;</code></pre></div>
|
||||
<p>It’s also good to be aware of <a href="struct.File.html#method.set_max_buf_size" title="method tokio::fs::File::set_max_buf_size"><code>File::set_max_buf_size</code></a>, which controls the
|
||||
maximum amount of bytes that Tokio’s <a href="struct.File.html" title="struct tokio::fs::File"><code>File</code></a> will read or write in a single
|
||||
<a href="../task/fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a> call. The default is two megabytes, but this is subject
|
||||
to change.</p>
|
||||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.DirBuilder.html" title="struct tokio::fs::DirBuilder">DirBuilder</a></div><div class="desc docblock-short">A builder for creating directories in various manners.</div></li><li><div class="item-name"><a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a></div><div class="desc docblock-short">Entries returned by the <a href="struct.ReadDir.html" title="struct tokio::fs::ReadDir"><code>ReadDir</code></a> stream.</div></li><li><div class="item-name"><a class="struct" href="struct.File.html" title="struct tokio::fs::File">File</a></div><div class="desc docblock-short">A reference to an open file on the filesystem.</div></li><li><div class="item-name"><a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">Open<wbr>Options</a></div><div class="desc docblock-short">Options and flags which can be used to configure how a file is opened.</div></li><li><div class="item-name"><a class="struct" href="struct.ReadDir.html" title="struct tokio::fs::ReadDir">ReadDir</a></div><div class="desc docblock-short">Reads the entries in a directory.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.canonicalize.html" title="fn tokio::fs::canonicalize">canonicalize</a></div><div class="desc docblock-short">Returns the canonical, absolute form of a path with all intermediate
|
||||
components normalized and symbolic links resolved.</div></li><li><div class="item-name"><a class="fn" href="fn.copy.html" title="fn tokio::fs::copy">copy</a></div><div class="desc docblock-short">Copies the contents of one file to another. This function will also copy the permission bits
|
||||
of the original file to the destination file.
|
||||
This function will overwrite the contents of to.</div></li><li><div class="item-name"><a class="fn" href="fn.create_dir.html" title="fn tokio::fs::create_dir">create_<wbr>dir</a></div><div class="desc docblock-short">Creates a new, empty directory at the provided path.</div></li><li><div class="item-name"><a class="fn" href="fn.create_dir_all.html" title="fn tokio::fs::create_dir_all">create_<wbr>dir_<wbr>all</a></div><div class="desc docblock-short">Recursively creates a directory and all of its parent components if they
|
||||
are missing.</div></li><li><div class="item-name"><a class="fn" href="fn.hard_link.html" title="fn tokio::fs::hard_link">hard_<wbr>link</a></div><div class="desc docblock-short">Creates a new hard link on the filesystem.</div></li><li><div class="item-name"><a class="fn" href="fn.metadata.html" title="fn tokio::fs::metadata">metadata</a></div><div class="desc docblock-short">Given a path, queries the file system to get information about a file,
|
||||
directory, etc.</div></li><li><div class="item-name"><a class="fn" href="fn.read.html" title="fn tokio::fs::read">read</a></div><div class="desc docblock-short">Reads the entire contents of a file into a bytes vector.</div></li><li><div class="item-name"><a class="fn" href="fn.read_dir.html" title="fn tokio::fs::read_dir">read_<wbr>dir</a></div><div class="desc docblock-short">Returns a stream over the entries within a directory.</div></li><li><div class="item-name"><a class="fn" href="fn.read_link.html" title="fn tokio::fs::read_link">read_<wbr>link</a></div><div class="desc docblock-short">Reads a symbolic link, returning the file that the link points to.</div></li><li><div class="item-name"><a class="fn" href="fn.read_to_string.html" title="fn tokio::fs::read_to_string">read_<wbr>to_<wbr>string</a></div><div class="desc docblock-short">Creates a future which will open a file for reading and read the entire
|
||||
contents into a string and return said string.</div></li><li><div class="item-name"><a class="fn" href="fn.remove_dir.html" title="fn tokio::fs::remove_dir">remove_<wbr>dir</a></div><div class="desc docblock-short">Removes an existing, empty directory.</div></li><li><div class="item-name"><a class="fn" href="fn.remove_dir_all.html" title="fn tokio::fs::remove_dir_all">remove_<wbr>dir_<wbr>all</a></div><div class="desc docblock-short">Removes a directory at this path, after removing all its contents. Use carefully!</div></li><li><div class="item-name"><a class="fn" href="fn.remove_file.html" title="fn tokio::fs::remove_file">remove_<wbr>file</a></div><div class="desc docblock-short">Removes a file from the filesystem.</div></li><li><div class="item-name"><a class="fn" href="fn.rename.html" title="fn tokio::fs::rename">rename</a></div><div class="desc docblock-short">Renames a file or directory to a new name, replacing the original file if
|
||||
<code>to</code> already exists.</div></li><li><div class="item-name"><a class="fn" href="fn.set_permissions.html" title="fn tokio::fs::set_permissions">set_<wbr>permissions</a></div><div class="desc docblock-short">Changes the permissions found on a file or a directory.</div></li><li><div class="item-name"><a class="fn" href="fn.symlink.html" title="fn tokio::fs::symlink">symlink</a></div><div class="desc docblock-short">Creates a new symbolic link on the filesystem.</div></li><li><div class="item-name"><a class="fn" href="fn.symlink_metadata.html" title="fn tokio::fs::symlink_metadata">symlink_<wbr>metadata</a></div><div class="desc docblock-short">Queries the file system metadata for a path.</div></li><li><div class="item-name"><a class="fn" href="fn.try_exists.html" title="fn tokio::fs::try_exists">try_<wbr>exists</a></div><div class="desc docblock-short">Returns <code>Ok(true)</code> if the path points at an existing entity.</div></li><li><div class="item-name"><a class="fn" href="fn.write.html" title="fn tokio::fs::write">write</a></div><div class="desc docblock-short">Creates a future that will open a file for writing and write the entire
|
||||
contents of <code>contents</code> to it.</div></li></ul></section></div></main></body></html>
|
||||
11
tokio/fs/metadata/fn.metadata.html
Normal file
11
tokio/fs/metadata/fn.metadata.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.metadata.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.metadata.html">../../../tokio/fs/fn.metadata.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.metadata.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/open_options/struct.OpenOptions.html
Normal file
11
tokio/fs/open_options/struct.OpenOptions.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/struct.OpenOptions.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/struct.OpenOptions.html">../../../tokio/fs/struct.OpenOptions.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/struct.OpenOptions.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/read/fn.read.html
Normal file
11
tokio/fs/read/fn.read.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.read.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.read.html">../../../tokio/fs/fn.read.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.read.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/read_dir/fn.read_dir.html
Normal file
11
tokio/fs/read_dir/fn.read_dir.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.read_dir.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.read_dir.html">../../../tokio/fs/fn.read_dir.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.read_dir.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/read_dir/struct.DirEntry.html
Normal file
11
tokio/fs/read_dir/struct.DirEntry.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/struct.DirEntry.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/struct.DirEntry.html">../../../tokio/fs/struct.DirEntry.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/struct.DirEntry.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/read_dir/struct.ReadDir.html
Normal file
11
tokio/fs/read_dir/struct.ReadDir.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/struct.ReadDir.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/struct.ReadDir.html">../../../tokio/fs/struct.ReadDir.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/struct.ReadDir.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/read_link/fn.read_link.html
Normal file
11
tokio/fs/read_link/fn.read_link.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.read_link.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.read_link.html">../../../tokio/fs/fn.read_link.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.read_link.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/read_to_string/fn.read_to_string.html
Normal file
11
tokio/fs/read_to_string/fn.read_to_string.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.read_to_string.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.read_to_string.html">../../../tokio/fs/fn.read_to_string.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.read_to_string.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/remove_dir/fn.remove_dir.html
Normal file
11
tokio/fs/remove_dir/fn.remove_dir.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.remove_dir.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.remove_dir.html">../../../tokio/fs/fn.remove_dir.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.remove_dir.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/remove_dir_all/fn.remove_dir_all.html
Normal file
11
tokio/fs/remove_dir_all/fn.remove_dir_all.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.remove_dir_all.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.remove_dir_all.html">../../../tokio/fs/fn.remove_dir_all.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.remove_dir_all.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/remove_file/fn.remove_file.html
Normal file
11
tokio/fs/remove_file/fn.remove_file.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.remove_file.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.remove_file.html">../../../tokio/fs/fn.remove_file.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.remove_file.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/rename/fn.rename.html
Normal file
11
tokio/fs/rename/fn.rename.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.rename.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.rename.html">../../../tokio/fs/fn.rename.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.rename.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/set_permissions/fn.set_permissions.html
Normal file
11
tokio/fs/set_permissions/fn.set_permissions.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.set_permissions.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.set_permissions.html">../../../tokio/fs/fn.set_permissions.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.set_permissions.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
1
tokio/fs/sidebar-items.js
Normal file
1
tokio/fs/sidebar-items.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
window.SIDEBAR_ITEMS = {"fn":["canonicalize","copy","create_dir","create_dir_all","hard_link","metadata","read","read_dir","read_link","read_to_string","remove_dir","remove_dir_all","remove_file","rename","set_permissions","symlink","symlink_metadata","try_exists","write"],"struct":["DirBuilder","DirEntry","File","OpenOptions","ReadDir"]};
|
||||
64
tokio/fs/struct.DirBuilder.html
Normal file
64
tokio/fs/struct.DirBuilder.html
Normal file
File diff suppressed because one or more lines are too long
93
tokio/fs/struct.DirEntry.html
Normal file
93
tokio/fs/struct.DirEntry.html
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<!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="Entries returned by the `ReadDir` stream."><title>DirEntry in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc struct"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">DirEntry</a></h2><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.file_name" title="file_name">file_name</a></li><li><a href="#method.file_type" title="file_type">file_type</a></li><li><a href="#method.ino" title="ino">ino</a></li><li><a href="#method.metadata" title="metadata">metadata</a></li><li><a href="#method.path" title="path">path</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Debug-for-DirEntry" title="Debug">Debug</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Freeze-for-DirEntry" title="Freeze">Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-DirEntry" title="RefUnwindSafe">RefUnwindSafe</a></li><li><a href="#impl-Send-for-DirEntry" title="Send">Send</a></li><li><a href="#impl-Sync-for-DirEntry" title="Sync">Sync</a></li><li><a href="#impl-Unpin-for-DirEntry" title="Unpin">Unpin</a></li><li><a href="#impl-UnwindSafe-for-DirEntry" title="UnwindSafe">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow<T>">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut<T>">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-T" title="From<T>">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into<U>">Into<U></a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom<U>">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto<U>">TryInto<U></a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Struct <span class="struct">DirEntry</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/read_dir.rs.html#200-212">Source</a> </span></div><pre class="rust item-decl"><code>pub struct DirEntry { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Entries returned by the <a href="struct.ReadDir.html" title="struct tokio::fs::ReadDir"><code>ReadDir</code></a> stream.</p>
|
||||
<p>This is a specialized version of <a href="https://doc.rust-lang.org/1.84.1/std/fs/struct.DirEntry.html" title="struct std::fs::DirEntry"><code>std::fs::DirEntry</code></a> for usage from the
|
||||
Tokio runtime.</p>
|
||||
<p>An instance of <code>DirEntry</code> represents an entry inside of a directory on the
|
||||
filesystem. Each entry can be inspected via methods to learn about the full
|
||||
path or possibly other metadata through per-platform extension traits.</p>
|
||||
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-DirEntry" class="impl"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#164-186">Source</a><a href="#impl-DirEntry" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.ino" class="method"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#183-185">Source</a><h4 class="code-header">pub fn <a href="#method.ino" class="fn">ino</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u64.html">u64</a></h4></section></summary><div class="docblock"><p>Returns the underlying <code>d_ino</code> field in the contained <code>dirent</code>
|
||||
structure.</p>
|
||||
<h5 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h5>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>entries = fs::read_dir(<span class="string">"."</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(entry) = entries.next_entry().<span class="kw">await</span><span class="question-mark">? </span>{
|
||||
<span class="comment">// Here, `entry` is a `DirEntry`.
|
||||
</span><span class="macro">println!</span>(<span class="string">"{:?}: {}"</span>, entry.file_name(), entry.ino());
|
||||
}</code></pre></div>
|
||||
</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-DirEntry-1" class="impl"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#214-357">Source</a><a href="#impl-DirEntry-1" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.path" class="method"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#244-246">Source</a><h4 class="code-header">pub fn <a href="#method.path" class="fn">path</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a></h4></section></summary><div class="docblock"><p>Returns the full path to the file that this entry represents.</p>
|
||||
<p>The full path is created by joining the original path to <code>read_dir</code>
|
||||
with the filename of this entry.</p>
|
||||
<h5 id="examples-1"><a class="doc-anchor" href="#examples-1">§</a>Examples</h5>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>entries = fs::read_dir(<span class="string">"."</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(entry) = entries.next_entry().<span class="kw">await</span><span class="question-mark">? </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"{:?}"</span>, entry.path());
|
||||
}</code></pre></div>
|
||||
<p>This prints output like:</p>
|
||||
<div class="example-wrap"><pre class="language-text"><code>"./whatever.txt"
|
||||
"./foo.html"
|
||||
"./hello_world.rs"</code></pre></div>
|
||||
<p>The exact text, of course, depends on what files you have in <code>.</code>.</p>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.file_name" class="method"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#265-267">Source</a><h4 class="code-header">pub fn <a href="#method.file_name" class="fn">file_name</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/ffi/os_str/struct.OsString.html" title="struct std::ffi::os_str::OsString">OsString</a></h4></section></summary><div class="docblock"><p>Returns the bare file name of this directory entry without any other
|
||||
leading path component.</p>
|
||||
<h5 id="examples-2"><a class="doc-anchor" href="#examples-2">§</a>Examples</h5>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>entries = fs::read_dir(<span class="string">"."</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(entry) = entries.next_entry().<span class="kw">await</span><span class="question-mark">? </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"{:?}"</span>, entry.file_name());
|
||||
}</code></pre></div>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.metadata" class="method"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#299-302">Source</a><h4 class="code-header">pub async fn <a href="#method.metadata" class="fn">metadata</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/fs/struct.Metadata.html" title="struct std::fs::Metadata">Metadata</a>></h4></section></summary><div class="docblock"><p>Returns the metadata for the file that this entry points at.</p>
|
||||
<p>This function will not traverse symlinks if this entry points at a
|
||||
symlink.</p>
|
||||
<h5 id="platform-specific-behavior"><a class="doc-anchor" href="#platform-specific-behavior">§</a>Platform-specific behavior</h5>
|
||||
<p>On Windows this function is cheap to call (no extra system calls
|
||||
needed), but on Unix platforms this function is the equivalent of
|
||||
calling <code>symlink_metadata</code> on the path.</p>
|
||||
<h5 id="examples-3"><a class="doc-anchor" href="#examples-3">§</a>Examples</h5>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>entries = fs::read_dir(<span class="string">"."</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(entry) = entries.next_entry().<span class="kw">await</span><span class="question-mark">? </span>{
|
||||
<span class="kw">if let </span><span class="prelude-val">Ok</span>(metadata) = entry.metadata().<span class="kw">await </span>{
|
||||
<span class="comment">// Now let's show our entry's permissions!
|
||||
</span><span class="macro">println!</span>(<span class="string">"{:?}: {:?}"</span>, entry.path(), metadata.permissions());
|
||||
} <span class="kw">else </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"Couldn't get file type for {:?}"</span>, entry.path());
|
||||
}
|
||||
}</code></pre></div>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.file_type" class="method"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#334-350">Source</a><h4 class="code-header">pub async fn <a href="#method.file_type" class="fn">file_type</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a>></h4></section></summary><div class="docblock"><p>Returns the file type for the file that this entry points at.</p>
|
||||
<p>This function will not traverse symlinks if this entry points at a
|
||||
symlink.</p>
|
||||
<h5 id="platform-specific-behavior-1"><a class="doc-anchor" href="#platform-specific-behavior-1">§</a>Platform-specific behavior</h5>
|
||||
<p>On Windows and most Unix platforms this function is free (no extra
|
||||
system calls needed), but some Unix platforms may require the equivalent
|
||||
call to <code>symlink_metadata</code> to learn about the target file type.</p>
|
||||
<h5 id="examples-4"><a class="doc-anchor" href="#examples-4">§</a>Examples</h5>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>entries = fs::read_dir(<span class="string">"."</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(entry) = entries.next_entry().<span class="kw">await</span><span class="question-mark">? </span>{
|
||||
<span class="kw">if let </span><span class="prelude-val">Ok</span>(file_type) = entry.file_type().<span class="kw">await </span>{
|
||||
<span class="comment">// Now let's show our entry's file type!
|
||||
</span><span class="macro">println!</span>(<span class="string">"{:?}: {:?}"</span>, entry.path(), file_type);
|
||||
} <span class="kw">else </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"Couldn't get file type for {:?}"</span>, entry.path());
|
||||
}
|
||||
}</code></pre></div>
|
||||
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-DirEntry" class="impl"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#199">Source</a><a href="#impl-Debug-for-DirEntry" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#199">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-DirEntry" class="impl"><a href="#impl-Freeze-for-DirEntry" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a></h3></section><section id="impl-RefUnwindSafe-for-DirEntry" class="impl"><a href="#impl-RefUnwindSafe-for-DirEntry" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a></h3></section><section id="impl-Send-for-DirEntry" class="impl"><a href="#impl-Send-for-DirEntry" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a></h3></section><section id="impl-Sync-for-DirEntry" class="impl"><a href="#impl-Sync-for-DirEntry" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a></h3></section><section id="impl-Unpin-for-DirEntry" class="impl"><a href="#impl-Unpin-for-DirEntry" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a></h3></section><section id="impl-UnwindSafe-for-DirEntry" class="impl"><a href="#impl-UnwindSafe-for-DirEntry" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/any.rs.html#138">Source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
||||
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/any.rs.html#139">Source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#209">Source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
||||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#211">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#217">Source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
||||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#218">Source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#765">Source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#768">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
||||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#748-750">Source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<div class="where">where
|
||||
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#758">Source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
|
||||
<p>That is, this conversion is whatever the implementation of
|
||||
<code><a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
||||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#805-807">Source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
|
||||
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#809">Source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#812">Source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#790-792">Source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<div class="where">where
|
||||
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#794">Source</a><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#797">Source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main></body></html>
|
||||
371
tokio/fs/struct.File.html
Normal file
371
tokio/fs/struct.File.html
Normal file
File diff suppressed because one or more lines are too long
274
tokio/fs/struct.OpenOptions.html
Normal file
274
tokio/fs/struct.OpenOptions.html
Normal file
File diff suppressed because one or more lines are too long
41
tokio/fs/struct.ReadDir.html
Normal file
41
tokio/fs/struct.ReadDir.html
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<!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="Reads the entries in a directory."><title>ReadDir in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc struct"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">ReadDir</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#errors" title="Errors">Errors</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.next_entry" title="next_entry">next_entry</a></li><li><a href="#method.poll_next_entry" title="poll_next_entry">poll_next_entry</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Debug-for-ReadDir" title="Debug">Debug</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-RefUnwindSafe-for-ReadDir" title="!RefUnwindSafe">!RefUnwindSafe</a></li><li><a href="#impl-UnwindSafe-for-ReadDir" title="!UnwindSafe">!UnwindSafe</a></li><li><a href="#impl-Freeze-for-ReadDir" title="Freeze">Freeze</a></li><li><a href="#impl-Send-for-ReadDir" title="Send">Send</a></li><li><a href="#impl-Sync-for-ReadDir" title="Sync">Sync</a></li><li><a href="#impl-Unpin-for-ReadDir" title="Unpin">Unpin</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow<T>">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut<T>">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-T" title="From<T>">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into<U>">Into<U></a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom<U>">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto<U>">TryInto<U></a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></span><h1>Struct <span class="struct">ReadDir</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/read_dir.rs.html#64">Source</a> </span></div><pre class="rust item-decl"><code>pub struct ReadDir(<span class="comment">/* private fields */</span>);</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Reads the entries in a directory.</p>
|
||||
<p>This struct is returned from the <a href="fn.read_dir.html" title="fn tokio::fs::read_dir"><code>read_dir</code></a> function of this module and
|
||||
will yield instances of <a href="struct.DirEntry.html" title="struct tokio::fs::DirEntry"><code>DirEntry</code></a>. Through a <a href="struct.DirEntry.html" title="struct tokio::fs::DirEntry"><code>DirEntry</code></a> information
|
||||
like the entry’s path and possibly other metadata can be learned.</p>
|
||||
<p>A <code>ReadDir</code> can be turned into a <code>Stream</code> with <a href="https://docs.rs/tokio-stream/0.1/tokio_stream/wrappers/struct.ReadDirStream.html"><code>ReadDirStream</code></a>.</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<p>This stream will return an <a href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html#variant.Err" title="variant core::result::Result::Err"><code>Err</code></a> if there’s some sort of intermittent
|
||||
IO error during iteration.</p>
|
||||
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-ReadDir" class="impl"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#72-157">Source</a><a href="#impl-ReadDir" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.ReadDir.html" title="struct tokio::fs::ReadDir">ReadDir</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.next_entry" class="method"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#78-81">Source</a><h4 class="code-header">pub async fn <a href="#method.next_entry" class="fn">next_entry</a>(&mut self) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a>>></h4></section></summary><div class="docblock"><p>Returns the next entry in the directory stream.</p>
|
||||
<h5 id="cancel-safety"><a class="doc-anchor" href="#cancel-safety">§</a>Cancel safety</h5>
|
||||
<p>This method is cancellation safe.</p>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.poll_next_entry" class="method"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#101-125">Source</a><h4 class="code-header">pub fn <a href="#method.poll_next_entry" class="fn">poll_next_entry</a>(
|
||||
&mut self,
|
||||
cx: &mut <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a><'_>,
|
||||
) -> <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a><<a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="struct.DirEntry.html" title="struct tokio::fs::DirEntry">DirEntry</a>>>></h4></section></summary><div class="docblock"><p>Polls for the next directory entry in the stream.</p>
|
||||
<p>This method returns:</p>
|
||||
<ul>
|
||||
<li><code>Poll::Pending</code> if the next directory entry is not yet available.</li>
|
||||
<li><code>Poll::Ready(Ok(Some(entry)))</code> if the next directory entry is available.</li>
|
||||
<li><code>Poll::Ready(Ok(None))</code> if there are no more directory entries in this
|
||||
stream.</li>
|
||||
<li><code>Poll::Ready(Err(err))</code> if an IO error occurred while reading the next
|
||||
directory entry.</li>
|
||||
</ul>
|
||||
<p>When the method returns <code>Poll::Pending</code>, the <code>Waker</code> in the provided
|
||||
<code>Context</code> is scheduled to receive a wakeup when the next directory entry
|
||||
becomes available on the underlying IO resource.</p>
|
||||
<p>Note that on multiple calls to <code>poll_next_entry</code>, only the <code>Waker</code> from
|
||||
the <code>Context</code> passed to the most recent call is scheduled to receive a
|
||||
wakeup.</p>
|
||||
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-ReadDir" class="impl"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#62">Source</a><a href="#impl-Debug-for-ReadDir" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.ReadDir.html" title="struct tokio::fs::ReadDir">ReadDir</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../../src/tokio/fs/read_dir.rs.html#62">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-ReadDir" class="impl"><a href="#impl-Freeze-for-ReadDir" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.ReadDir.html" title="struct tokio::fs::ReadDir">ReadDir</a></h3></section><section id="impl-RefUnwindSafe-for-ReadDir" class="impl"><a href="#impl-RefUnwindSafe-for-ReadDir" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.ReadDir.html" title="struct tokio::fs::ReadDir">ReadDir</a></h3></section><section id="impl-Send-for-ReadDir" class="impl"><a href="#impl-Send-for-ReadDir" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.ReadDir.html" title="struct tokio::fs::ReadDir">ReadDir</a></h3></section><section id="impl-Sync-for-ReadDir" class="impl"><a href="#impl-Sync-for-ReadDir" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.ReadDir.html" title="struct tokio::fs::ReadDir">ReadDir</a></h3></section><section id="impl-Unpin-for-ReadDir" class="impl"><a href="#impl-Unpin-for-ReadDir" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.ReadDir.html" title="struct tokio::fs::ReadDir">ReadDir</a></h3></section><section id="impl-UnwindSafe-for-ReadDir" class="impl"><a href="#impl-UnwindSafe-for-ReadDir" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.ReadDir.html" title="struct tokio::fs::ReadDir">ReadDir</a></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/any.rs.html#138">Source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
||||
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/any.rs.html#139">Source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#209">Source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
||||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#211">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#217">Source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
||||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#218">Source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#765">Source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#768">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
||||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#748-750">Source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<div class="where">where
|
||||
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#758">Source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
|
||||
<p>That is, this conversion is whatever the implementation of
|
||||
<code><a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
||||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#805-807">Source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
|
||||
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#809">Source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#812">Source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#790-792">Source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<div class="where">where
|
||||
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#794">Source</a><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#797">Source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main></body></html>
|
||||
11
tokio/fs/symlink/fn.symlink.html
Normal file
11
tokio/fs/symlink/fn.symlink.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.symlink.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.symlink.html">../../../tokio/fs/fn.symlink.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.symlink.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/symlink_metadata/fn.symlink_metadata.html
Normal file
11
tokio/fs/symlink_metadata/fn.symlink_metadata.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.symlink_metadata.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.symlink_metadata.html">../../../tokio/fs/fn.symlink_metadata.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.symlink_metadata.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/try_exists/fn.try_exists.html
Normal file
11
tokio/fs/try_exists/fn.try_exists.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.try_exists.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.try_exists.html">../../../tokio/fs/fn.try_exists.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.try_exists.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/fs/write/fn.write.html
Normal file
11
tokio/fs/write/fn.write.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/fs/fn.write.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/fs/fn.write.html">../../../tokio/fs/fn.write.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/fs/fn.write.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
299
tokio/index.html
Normal file
299
tokio/index.html
Normal file
|
|
@ -0,0 +1,299 @@
|
|||
<!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 runtime for writing reliable network applications without compromising speed."><title>tokio - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#a-tour-of-tokio" title="A Tour of Tokio">A Tour of Tokio</a><ul><li><a href="#authoring-applications" title="Authoring applications">Authoring applications</a></li><li><a href="#authoring-libraries" title="Authoring libraries">Authoring libraries</a></li><li><a href="#working-with-tasks" title="Working With Tasks">Working With Tasks</a></li><li><a href="#cpu-bound-tasks-and-blocking-code" title="CPU-bound tasks and blocking code">CPU-bound tasks and blocking code</a></li><li><a href="#asynchronous-io" title="Asynchronous IO">Asynchronous IO</a></li></ul></li><li><a href="#examples" title="Examples">Examples</a><ul><li><a href="#feature-flags" title="Feature flags">Feature flags</a></li><li><a href="#supported-platforms" title="Supported platforms">Supported platforms</a></li></ul></li></ul><h3><a href="#reexports">Crate Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#macros" title="Macros">Macros</a></li><li><a href="#attributes" title="Attribute Macros">Attribute Macros</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>tokio</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/tokio/lib.rs.html#1-699">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A runtime for writing reliable network applications without compromising speed.</p>
|
||||
<p>Tokio is an event-driven, non-blocking I/O platform for writing asynchronous
|
||||
applications with the Rust programming language. At a high level, it
|
||||
provides a few major components:</p>
|
||||
<ul>
|
||||
<li>Tools for <a href="#working-with-tasks">working with asynchronous tasks</a>, including
|
||||
<a href="sync/index.html" title="mod tokio::sync">synchronization primitives and channels</a> and <a href="time/index.html" title="mod tokio::time">timeouts, sleeps, and
|
||||
intervals</a>.</li>
|
||||
<li>APIs for <a href="#asynchronous-io">performing asynchronous I/O</a>, including <a href="net/index.html" title="mod tokio::net">TCP and UDP</a> sockets,
|
||||
<a href="fs/index.html" title="mod tokio::fs">filesystem</a> operations, and <a href="process/index.html" title="mod tokio::process">process</a> and <a href="signal/index.html" title="mod tokio::signal">signal</a> management.</li>
|
||||
<li>A <a href="runtime/index.html" title="mod tokio::runtime">runtime</a> for executing asynchronous code, including a task scheduler,
|
||||
an I/O driver backed by the operating system’s event queue (<code>epoll</code>, <code>kqueue</code>,
|
||||
<code>IOCP</code>, etc…), and a high performance timer.</li>
|
||||
</ul>
|
||||
<p>Guide level documentation is found on the <a href="https://tokio.rs/tokio/tutorial">website</a>.</p>
|
||||
<h2 id="a-tour-of-tokio"><a class="doc-anchor" href="#a-tour-of-tokio">§</a>A Tour of Tokio</h2>
|
||||
<p>Tokio consists of a number of modules that provide a range of functionality
|
||||
essential for implementing asynchronous applications in Rust. In this
|
||||
section, we will take a brief tour of Tokio, summarizing the major APIs and
|
||||
their uses.</p>
|
||||
<p>The easiest way to get started is to enable all features. Do this by
|
||||
enabling the <code>full</code> feature flag:</p>
|
||||
<div class="example-wrap"><pre class="language-toml"><code>tokio = { version = "1", features = ["full"] }</code></pre></div><h4 id="authoring-applications"><a class="doc-anchor" href="#authoring-applications">§</a>Authoring applications</h4>
|
||||
<p>Tokio is great for writing applications and most users in this case shouldn’t
|
||||
worry too much about what features they should pick. If you’re unsure, we suggest
|
||||
going with <code>full</code> to ensure that you don’t run into any road blocks while you’re
|
||||
building your application.</p>
|
||||
<h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</h5>
|
||||
<p>This example shows the quickest way to get started with Tokio.</p>
|
||||
<div class="example-wrap"><pre class="language-toml"><code>tokio = { version = "1", features = ["full"] }</code></pre></div><h4 id="authoring-libraries"><a class="doc-anchor" href="#authoring-libraries">§</a>Authoring libraries</h4>
|
||||
<p>As a library author your goal should be to provide the lightest weight crate
|
||||
that is based on Tokio. To achieve this you should ensure that you only enable
|
||||
the features you need. This allows users to pick up your crate without having
|
||||
to enable unnecessary features.</p>
|
||||
<h5 id="example-1"><a class="doc-anchor" href="#example-1">§</a>Example</h5>
|
||||
<p>This example shows how you may want to import features for a library that just
|
||||
needs to <code>tokio::spawn</code> and use a <code>TcpStream</code>.</p>
|
||||
<div class="example-wrap"><pre class="language-toml"><code>tokio = { version = "1", features = ["rt", "net"] }</code></pre></div><h3 id="working-with-tasks"><a class="doc-anchor" href="#working-with-tasks">§</a>Working With Tasks</h3>
|
||||
<p>Asynchronous programs in Rust are based around lightweight, non-blocking
|
||||
units of execution called <a href="#working-with-tasks"><em>tasks</em></a>. The <a href="task/index.html" title="mod tokio::task"><code>tokio::task</code></a> module provides
|
||||
important tools for working with tasks:</p>
|
||||
<ul>
|
||||
<li>The <a href="task/fn.spawn.html" title="fn tokio::task::spawn"><code>spawn</code></a> function and <a href="task/struct.JoinHandle.html" title="struct tokio::task::JoinHandle"><code>JoinHandle</code></a> type, for scheduling a new task
|
||||
on the Tokio runtime and awaiting the output of a spawned task, respectively,</li>
|
||||
<li>Functions for <a href="task/index.html#blocking-and-yielding">running blocking operations</a> in an asynchronous
|
||||
task context.</li>
|
||||
</ul>
|
||||
<p>The <a href="task/index.html" title="mod tokio::task"><code>tokio::task</code></a> module is present only when the “rt” feature flag
|
||||
is enabled.</p>
|
||||
<p>The <a href="sync/index.html" title="mod tokio::sync"><code>tokio::sync</code></a> module contains synchronization primitives to use when
|
||||
needing to communicate or share data. These include:</p>
|
||||
<ul>
|
||||
<li>channels (<a href="sync/oneshot/index.html" title="mod tokio::sync::oneshot"><code>oneshot</code></a>, <a href="sync/mpsc/index.html" title="mod tokio::sync::mpsc"><code>mpsc</code></a>, <a href="sync/watch/index.html" title="mod tokio::sync::watch"><code>watch</code></a>, and <a href="sync/broadcast/index.html" title="mod tokio::sync::broadcast"><code>broadcast</code></a>), for sending values
|
||||
between tasks,</li>
|
||||
<li>a non-blocking <a href="sync/struct.Mutex.html" title="struct tokio::sync::Mutex"><code>Mutex</code></a>, for controlling access to a shared, mutable
|
||||
value,</li>
|
||||
<li>an asynchronous <a href="sync/struct.Barrier.html" title="struct tokio::sync::Barrier"><code>Barrier</code></a> type, for multiple tasks to synchronize before
|
||||
beginning a computation.</li>
|
||||
</ul>
|
||||
<p>The <code>tokio::sync</code> module is present only when the “sync” feature flag is
|
||||
enabled.</p>
|
||||
<p>The <a href="time/index.html" title="mod tokio::time"><code>tokio::time</code></a> module provides utilities for tracking time and
|
||||
scheduling work. This includes functions for setting <a href="time/fn.timeout.html" title="fn tokio::time::timeout">timeouts</a> for
|
||||
tasks, <a href="time/fn.sleep.html" title="fn tokio::time::sleep">sleeping</a> work to run in the future, or <a href="time/fn.interval.html" title="fn tokio::time::interval">repeating an operation at an
|
||||
interval</a>.</p>
|
||||
<p>In order to use <code>tokio::time</code>, the “time” feature flag must be enabled.</p>
|
||||
<p>Finally, Tokio provides a <em>runtime</em> for executing asynchronous tasks. Most
|
||||
applications can use the <a href="attr.main.html"><code>#[tokio::main]</code></a> macro to run their code on the
|
||||
Tokio runtime. However, this macro provides only basic configuration options. As
|
||||
an alternative, the <a href="runtime/index.html" title="mod tokio::runtime"><code>tokio::runtime</code></a> module provides more powerful APIs for configuring
|
||||
and managing runtimes. You should use that module if the <code>#[tokio::main]</code> macro doesn’t
|
||||
provide the functionality you need.</p>
|
||||
<p>Using the runtime requires the “rt” or “rt-multi-thread” feature flags, to
|
||||
enable the current-thread <a href="runtime/index.html#current-thread-scheduler">single-threaded scheduler</a> and the <a href="runtime/index.html#multi-thread-scheduler">multi-thread
|
||||
scheduler</a>, respectively. See the <a href="runtime/index.html#runtime-scheduler"><code>runtime</code> module
|
||||
documentation</a> for details. In addition, the “macros” feature
|
||||
flag enables the <code>#[tokio::main]</code> and <code>#[tokio::test]</code> attributes.</p>
|
||||
<h3 id="cpu-bound-tasks-and-blocking-code"><a class="doc-anchor" href="#cpu-bound-tasks-and-blocking-code">§</a>CPU-bound tasks and blocking code</h3>
|
||||
<p>Tokio is able to concurrently run many tasks on a few threads by repeatedly
|
||||
swapping the currently running task on each thread. However, this kind of
|
||||
swapping can only happen at <code>.await</code> points, so code that spends a long time
|
||||
without reaching an <code>.await</code> will prevent other tasks from running. To
|
||||
combat this, Tokio provides two kinds of threads: Core threads and blocking threads.</p>
|
||||
<p>The core threads are where all asynchronous code runs, and Tokio will by default
|
||||
spawn one for each CPU core. You can use the environment variable <code>TOKIO_WORKER_THREADS</code>
|
||||
to override the default value.</p>
|
||||
<p>The blocking threads are spawned on demand, can be used to run blocking code
|
||||
that would otherwise block other tasks from running and are kept alive when
|
||||
not used for a certain amount of time which can be configured with <a href="runtime/struct.Builder.html#method.thread_keep_alive" title="method tokio::runtime::Builder::thread_keep_alive"><code>thread_keep_alive</code></a>.
|
||||
Since it is not possible for Tokio to swap out blocking tasks, like it
|
||||
can do with asynchronous code, the upper limit on the number of blocking
|
||||
threads is very large. These limits can be configured on the <a href="runtime/struct.Builder.html" title="struct tokio::runtime::Builder"><code>Builder</code></a>.</p>
|
||||
<p>To spawn a blocking task, you should use the <a href="task/fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a> function.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="comment">// This is running on a core thread.
|
||||
|
||||
</span><span class="kw">let </span>blocking_task = tokio::task::spawn_blocking(|| {
|
||||
<span class="comment">// This is running on a blocking thread.
|
||||
// Blocking here is ok.
|
||||
</span>});
|
||||
|
||||
<span class="comment">// We can wait for the blocking task like this:
|
||||
// If the blocking task panics, the unwrap below will propagate the
|
||||
// panic.
|
||||
</span>blocking_task.<span class="kw">await</span>.unwrap();
|
||||
}</code></pre></div>
|
||||
<p>If your code is CPU-bound and you wish to limit the number of threads used
|
||||
to run it, you should use a separate thread pool dedicated to CPU bound tasks.
|
||||
For example, you could consider using the <a href="https://docs.rs/rayon">rayon</a> library for CPU-bound
|
||||
tasks. It is also possible to create an extra Tokio runtime dedicated to
|
||||
CPU-bound tasks, but if you do this, you should be careful that the extra
|
||||
runtime runs <em>only</em> CPU-bound tasks, as IO-bound tasks on that runtime
|
||||
will behave poorly.</p>
|
||||
<p>Hint: If using rayon, you can use a <a href="sync/oneshot/index.html" title="mod tokio::sync::oneshot"><code>oneshot</code></a> channel to send the result back
|
||||
to Tokio when the rayon task finishes.</p>
|
||||
<h3 id="asynchronous-io"><a class="doc-anchor" href="#asynchronous-io">§</a>Asynchronous IO</h3>
|
||||
<p>As well as scheduling and running tasks, Tokio provides everything you need
|
||||
to perform input and output asynchronously.</p>
|
||||
<p>The <a href="io/index.html" title="mod tokio::io"><code>tokio::io</code></a> module provides Tokio’s asynchronous core I/O primitives,
|
||||
the <a href="io/trait.AsyncRead.html" title="trait tokio::io::AsyncRead"><code>AsyncRead</code></a>, <a href="io/trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite"><code>AsyncWrite</code></a>, and <a href="io/trait.AsyncBufRead.html" title="trait tokio::io::AsyncBufRead"><code>AsyncBufRead</code></a> traits. In addition,
|
||||
when the “io-util” feature flag is enabled, it also provides combinators and
|
||||
functions for working with these traits, forming as an asynchronous
|
||||
counterpart to <a href="https://doc.rust-lang.org/1.84.1/std/io/index.html" title="mod std::io"><code>std::io</code></a>.</p>
|
||||
<p>Tokio also includes APIs for performing various kinds of I/O and interacting
|
||||
with the operating system asynchronously. These include:</p>
|
||||
<ul>
|
||||
<li><a href="net/index.html" title="mod tokio::net"><code>tokio::net</code></a>, which contains non-blocking versions of <a href="net/tcp/index.html" title="mod tokio::net::tcp">TCP</a>, <a href="net/struct.UdpSocket.html" title="struct tokio::net::UdpSocket">UDP</a>, and
|
||||
<a href="net/unix/index.html" title="mod tokio::net::unix">Unix Domain Sockets</a> (enabled by the “net” feature flag),</li>
|
||||
<li><a href="fs/index.html" title="mod tokio::fs"><code>tokio::fs</code></a>, similar to <a href="https://doc.rust-lang.org/1.84.1/std/fs/index.html" title="mod std::fs"><code>std::fs</code></a> but for performing filesystem I/O
|
||||
asynchronously (enabled by the “fs” feature flag),</li>
|
||||
<li><a href="signal/index.html" title="mod tokio::signal"><code>tokio::signal</code></a>, for asynchronously handling Unix and Windows OS signals
|
||||
(enabled by the “signal” feature flag),</li>
|
||||
<li><a href="process/index.html" title="mod tokio::process"><code>tokio::process</code></a>, for spawning and managing child processes (enabled by
|
||||
the “process” feature flag).</li>
|
||||
</ul>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>A simple TCP echo server:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpListener;
|
||||
<span class="kw">use </span>tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> <span class="prelude-ty">Result</span><(), Box<<span class="kw">dyn </span>std::error::Error>> {
|
||||
<span class="kw">let </span>listener = TcpListener::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">loop </span>{
|
||||
<span class="kw">let </span>(<span class="kw-2">mut </span>socket, <span class="kw">_</span>) = listener.accept().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
tokio::spawn(<span class="kw">async move </span>{
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">1024</span>];
|
||||
|
||||
<span class="comment">// In a loop, read data from the socket and write the data back.
|
||||
</span><span class="kw">loop </span>{
|
||||
<span class="kw">let </span>n = <span class="kw">match </span>socket.read(<span class="kw-2">&mut </span>buf).<span class="kw">await </span>{
|
||||
<span class="comment">// socket closed
|
||||
</span><span class="prelude-val">Ok</span>(n) <span class="kw">if </span>n == <span class="number">0 </span>=> <span class="kw">return</span>,
|
||||
<span class="prelude-val">Ok</span>(n) => n,
|
||||
<span class="prelude-val">Err</span>(e) => {
|
||||
<span class="macro">eprintln!</span>(<span class="string">"failed to read from socket; err = {:?}"</span>, e);
|
||||
<span class="kw">return</span>;
|
||||
}
|
||||
};
|
||||
|
||||
<span class="comment">// Write the data back
|
||||
</span><span class="kw">if let </span><span class="prelude-val">Err</span>(e) = socket.write_all(<span class="kw-2">&</span>buf[<span class="number">0</span>..n]).<span class="kw">await </span>{
|
||||
<span class="macro">eprintln!</span>(<span class="string">"failed to write to socket; err = {:?}"</span>, e);
|
||||
<span class="kw">return</span>;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}</code></pre></div>
|
||||
<h3 id="feature-flags"><a class="doc-anchor" href="#feature-flags">§</a>Feature flags</h3>
|
||||
<p>Tokio uses a set of <a href="https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section">feature flags</a> to reduce the amount of compiled code. It
|
||||
is possible to just enable certain features over others. By default, Tokio
|
||||
does not enable any features but allows one to enable a subset for their use
|
||||
case. Below is a list of the available feature flags. You may also notice
|
||||
above each function, struct and trait there is listed one or more feature flags
|
||||
that are required for that item to be used. If you are new to Tokio it is
|
||||
recommended that you use the <code>full</code> feature flag which will enable all public APIs.
|
||||
Beware though that this will pull in many extra dependencies that you may not
|
||||
need.</p>
|
||||
<ul>
|
||||
<li><code>full</code>: Enables all features listed below except <code>test-util</code> and <code>tracing</code>.</li>
|
||||
<li><code>rt</code>: Enables <code>tokio::spawn</code>, the current-thread scheduler,
|
||||
and non-scheduler utilities.</li>
|
||||
<li><code>rt-multi-thread</code>: Enables the heavier, multi-threaded, work-stealing scheduler.</li>
|
||||
<li><code>io-util</code>: Enables the IO based <code>Ext</code> traits.</li>
|
||||
<li><code>io-std</code>: Enable <code>Stdout</code>, <code>Stdin</code> and <code>Stderr</code> types.</li>
|
||||
<li><code>net</code>: Enables <code>tokio::net</code> types such as <code>TcpStream</code>, <code>UnixStream</code> and
|
||||
<code>UdpSocket</code>, as well as (on Unix-like systems) <code>AsyncFd</code> and (on
|
||||
FreeBSD) <code>PollAio</code>.</li>
|
||||
<li><code>time</code>: Enables <code>tokio::time</code> types and allows the schedulers to enable
|
||||
the built in timer.</li>
|
||||
<li><code>process</code>: Enables <code>tokio::process</code> types.</li>
|
||||
<li><code>macros</code>: Enables <code>#[tokio::main]</code> and <code>#[tokio::test]</code> macros.</li>
|
||||
<li><code>sync</code>: Enables all <code>tokio::sync</code> types.</li>
|
||||
<li><code>signal</code>: Enables all <code>tokio::signal</code> types.</li>
|
||||
<li><code>fs</code>: Enables <code>tokio::fs</code> types.</li>
|
||||
<li><code>test-util</code>: Enables testing based infrastructure for the Tokio runtime.</li>
|
||||
<li><code>parking_lot</code>: As a potential optimization, use the <code>_parking_lot_</code> crate’s
|
||||
synchronization primitives internally. Also, this
|
||||
dependency is necessary to construct some of our primitives
|
||||
in a <code>const</code> context. <code>MSRV</code> may increase according to the
|
||||
<code>_parking_lot_</code> release in use.</li>
|
||||
</ul>
|
||||
<p><em>Note: <code>AsyncRead</code> and <code>AsyncWrite</code> traits do not require any features and are
|
||||
always available.</em></p>
|
||||
<h4 id="unstable-features"><a class="doc-anchor" href="#unstable-features">§</a>Unstable features</h4>
|
||||
<p>Some feature flags are only available when specifying the <code>tokio_unstable</code> flag:</p>
|
||||
<ul>
|
||||
<li><code>tracing</code>: Enables tracing events.</li>
|
||||
</ul>
|
||||
<p>Likewise, some parts of the API are only available with the same flag:</p>
|
||||
<ul>
|
||||
<li>[<code>task::Builder</code>]</li>
|
||||
<li>Some methods on <a href="task/struct.JoinSet.html" title="struct tokio::task::JoinSet"><code>task::JoinSet</code></a></li>
|
||||
<li><a href="runtime/struct.RuntimeMetrics.html" title="struct tokio::runtime::RuntimeMetrics"><code>runtime::RuntimeMetrics</code></a></li>
|
||||
<li>[<code>runtime::Builder::on_task_spawn</code>]</li>
|
||||
<li>[<code>runtime::Builder::on_task_terminate</code>]</li>
|
||||
<li>[<code>runtime::Builder::unhandled_panic</code>]</li>
|
||||
<li>[<code>runtime::TaskMeta</code>]</li>
|
||||
</ul>
|
||||
<p>This flag enables <strong>unstable</strong> features. The public API of these features
|
||||
may break in 1.x releases. To enable these features, the <code>--cfg tokio_unstable</code> argument must be passed to <code>rustc</code> when compiling. This
|
||||
serves to explicitly opt-in to features which may break semver conventions,
|
||||
since Cargo <a href="https://internals.rust-lang.org/t/feature-request-unstable-opt-in-non-transitive-crate-features/16193#why-not-a-crate-feature-2">does not yet directly support such opt-ins</a>.</p>
|
||||
<p>You can specify it in your project’s <code>.cargo/config.toml</code> file:</p>
|
||||
<div class="example-wrap"><pre class="language-toml"><code>[build]
|
||||
rustflags = ["--cfg", "tokio_unstable"]</code></pre></div><div class="warning">
|
||||
The <code>[build]</code> section does <strong>not</strong> go in a
|
||||
<code>Cargo.toml</code> file. Instead it must be placed in the Cargo config
|
||||
file <code>.cargo/config.toml</code>.
|
||||
</div>
|
||||
<p>Alternatively, you can specify it with an environment variable:</p>
|
||||
<div class="example-wrap"><pre class="language-sh"><code>## Many *nix shells:
|
||||
export RUSTFLAGS="--cfg tokio_unstable"
|
||||
cargo build</code></pre></div><div class="example-wrap"><pre class="language-powershell"><code>## Windows PowerShell:
|
||||
$Env:RUSTFLAGS="--cfg tokio_unstable"
|
||||
cargo build</code></pre></div><h3 id="supported-platforms"><a class="doc-anchor" href="#supported-platforms">§</a>Supported platforms</h3>
|
||||
<p>Tokio currently guarantees support for the following platforms:</p>
|
||||
<ul>
|
||||
<li>Linux</li>
|
||||
<li>Windows</li>
|
||||
<li>Android (API level 21)</li>
|
||||
<li>macOS</li>
|
||||
<li>iOS</li>
|
||||
<li>FreeBSD</li>
|
||||
</ul>
|
||||
<p>Tokio will continue to support these platforms in the future. However,
|
||||
future releases may change requirements such as the minimum required libc
|
||||
version on Linux, the API level on Android, or the supported FreeBSD
|
||||
release.</p>
|
||||
<p>Beyond the above platforms, Tokio is intended to work on all platforms
|
||||
supported by the mio crate. You can find a longer list <a href="https://crates.io/crates/mio#platforms">in mio’s
|
||||
documentation</a>. However, these additional platforms may
|
||||
become unsupported in the future.</p>
|
||||
<p>Note that Wine is considered to be a different platform from Windows. See
|
||||
mio’s documentation for more information on Wine support.</p>
|
||||
<h4 id="wasm-support"><a class="doc-anchor" href="#wasm-support">§</a><code>WASM</code> support</h4>
|
||||
<p>Tokio has some limited support for the <code>WASM</code> platform. Without the
|
||||
<code>tokio_unstable</code> flag, the following features are supported:</p>
|
||||
<ul>
|
||||
<li><code>sync</code></li>
|
||||
<li><code>macros</code></li>
|
||||
<li><code>io-util</code></li>
|
||||
<li><code>rt</code></li>
|
||||
<li><code>time</code></li>
|
||||
</ul>
|
||||
<p>Enabling any other feature (including <code>full</code>) will cause a compilation
|
||||
failure.</p>
|
||||
<p>The <code>time</code> module will only work on <code>WASM</code> platforms that have support for
|
||||
timers (e.g. wasm32-wasi). The timing functions will panic if used on a <code>WASM</code>
|
||||
platform that does not support timers.</p>
|
||||
<p>Note also that if the runtime becomes indefinitely idle, it will panic
|
||||
immediately instead of blocking forever. On platforms that don’t support
|
||||
time, this means that the runtime can never be idle in any way.</p>
|
||||
<h4 id="unstable-wasm-support"><a class="doc-anchor" href="#unstable-wasm-support">§</a>Unstable <code>WASM</code> support</h4>
|
||||
<p>Tokio also has unstable support for some additional <code>WASM</code> features. This
|
||||
requires the use of the <code>tokio_unstable</code> flag.</p>
|
||||
<p>Using this flag enables the use of <code>tokio::net</code> on the wasm32-wasi target.
|
||||
However, not all methods are available on the networking types as <code>WASI</code>
|
||||
currently does not support the creation of new sockets from within <code>WASM</code>.
|
||||
Because of this, sockets must currently be created via the <code>FromRawFd</code>
|
||||
trait.</p>
|
||||
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.spawn"><code>pub use task::<a class="fn" href="task/fn.spawn.html" title="fn tokio::task::spawn">spawn</a>;</code></div></li></ul><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="fs/index.html" title="mod tokio::fs">fs</a></div><div class="desc docblock-short">Asynchronous file utilities.</div></li><li><div class="item-name"><a class="mod" href="io/index.html" title="mod tokio::io">io</a></div><div class="desc docblock-short">Traits, helpers, and type definitions for asynchronous I/O functionality.</div></li><li><div class="item-name"><a class="mod" href="net/index.html" title="mod tokio::net">net</a></div><div class="desc docblock-short">TCP/UDP/Unix bindings for <code>tokio</code>.</div></li><li><div class="item-name"><a class="mod" href="process/index.html" title="mod tokio::process">process</a></div><div class="desc docblock-short">An implementation of asynchronous process management for Tokio.</div></li><li><div class="item-name"><a class="mod" href="runtime/index.html" title="mod tokio::runtime">runtime</a></div><div class="desc docblock-short">The Tokio runtime.</div></li><li><div class="item-name"><a class="mod" href="signal/index.html" title="mod tokio::signal">signal</a></div><div class="desc docblock-short">Asynchronous signal handling for Tokio.</div></li><li><div class="item-name"><a class="mod" href="stream/index.html" title="mod tokio::stream">stream</a></div><div class="desc docblock-short">Due to the <code>Stream</code> trait’s inclusion in <code>std</code> landing later than Tokio’s 1.0
|
||||
release, most of the Tokio stream utilities have been moved into the <a href="https://docs.rs/tokio-stream"><code>tokio-stream</code></a>
|
||||
crate.</div></li><li><div class="item-name"><a class="mod" href="sync/index.html" title="mod tokio::sync">sync</a></div><div class="desc docblock-short">Synchronization primitives for use in asynchronous contexts.</div></li><li><div class="item-name"><a class="mod" href="task/index.html" title="mod tokio::task">task</a></div><div class="desc docblock-short">Asynchronous green-threads.</div></li><li><div class="item-name"><a class="mod" href="time/index.html" title="mod tokio::time">time</a></div><div class="desc docblock-short">Utilities for tracking time.</div></li></ul><h2 id="macros" class="section-header">Macros<a href="#macros" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="macro" href="macro.join.html" title="macro tokio::join">join</a></div><div class="desc docblock-short">Waits on multiple concurrent branches, returning when <strong>all</strong> branches
|
||||
complete.</div></li><li><div class="item-name"><a class="macro" href="macro.pin.html" title="macro tokio::pin">pin</a></div><div class="desc docblock-short">Pins a value on the stack.</div></li><li><div class="item-name"><a class="macro" href="macro.select.html" title="macro tokio::select">select</a></div><div class="desc docblock-short">Waits on multiple concurrent branches, returning when the <strong>first</strong> branch
|
||||
completes, cancelling the remaining branches.</div></li><li><div class="item-name"><a class="macro" href="macro.task_local.html" title="macro tokio::task_local">task_<wbr>local</a></div><div class="desc docblock-short">Declares a new task-local key of type <a href="task/struct.LocalKey.html" title="struct tokio::task::LocalKey"><code>tokio::task::LocalKey</code></a>.</div></li><li><div class="item-name"><a class="macro" href="macro.try_join.html" title="macro tokio::try_join">try_<wbr>join</a></div><div class="desc docblock-short">Waits on multiple concurrent branches, returning when <strong>all</strong> branches
|
||||
complete with <code>Ok(_)</code> or on the first <code>Err(_)</code>.</div></li></ul><h2 id="attributes" class="section-header">Attribute Macros<a href="#attributes" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="attr" href="attr.main.html" title="attr tokio::main">main</a></div><div class="desc docblock-short">Marks async function to be executed by the selected runtime. This macro
|
||||
helps set up a <code>Runtime</code> without requiring the user to use
|
||||
<a href="../tokio/runtime/struct.Runtime.html">Runtime</a> or
|
||||
<a href="../tokio/runtime/struct.Builder.html">Builder</a> directly.</div></li><li><div class="item-name"><a class="attr" href="attr.test.html" title="attr tokio::test">test</a></div><div class="desc docblock-short">Marks async function to be executed by runtime, suitable to test environment.
|
||||
This macro helps set up a <code>Runtime</code> without requiring the user to use
|
||||
<a href="../tokio/runtime/struct.Runtime.html">Runtime</a> or
|
||||
<a href="../tokio/runtime/struct.Builder.html">Builder</a> directly.</div></li></ul></section></div></main></body></html>
|
||||
11
tokio/io/async_buf_read/trait.AsyncBufRead.html
Normal file
11
tokio/io/async_buf_read/trait.AsyncBufRead.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/trait.AsyncBufRead.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/trait.AsyncBufRead.html">../../../tokio/io/trait.AsyncBufRead.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/trait.AsyncBufRead.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/async_fd/struct.AsyncFd.html
Normal file
11
tokio/io/async_fd/struct.AsyncFd.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/unix/struct.AsyncFd.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/unix/struct.AsyncFd.html">../../../tokio/io/unix/struct.AsyncFd.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/unix/struct.AsyncFd.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/async_fd/struct.AsyncFdReadyGuard.html
Normal file
11
tokio/io/async_fd/struct.AsyncFdReadyGuard.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/unix/struct.AsyncFdReadyGuard.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/unix/struct.AsyncFdReadyGuard.html">../../../tokio/io/unix/struct.AsyncFdReadyGuard.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/unix/struct.AsyncFdReadyGuard.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/async_fd/struct.AsyncFdReadyMutGuard.html
Normal file
11
tokio/io/async_fd/struct.AsyncFdReadyMutGuard.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/unix/struct.AsyncFdReadyMutGuard.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/unix/struct.AsyncFdReadyMutGuard.html">../../../tokio/io/unix/struct.AsyncFdReadyMutGuard.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/unix/struct.AsyncFdReadyMutGuard.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/async_fd/struct.AsyncFdTryNewError.html
Normal file
11
tokio/io/async_fd/struct.AsyncFdTryNewError.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/unix/struct.AsyncFdTryNewError.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/unix/struct.AsyncFdTryNewError.html">../../../tokio/io/unix/struct.AsyncFdTryNewError.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/unix/struct.AsyncFdTryNewError.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/async_fd/struct.TryIoError.html
Normal file
11
tokio/io/async_fd/struct.TryIoError.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/unix/struct.TryIoError.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/unix/struct.TryIoError.html">../../../tokio/io/unix/struct.TryIoError.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/unix/struct.TryIoError.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/async_read/trait.AsyncRead.html
Normal file
11
tokio/io/async_read/trait.AsyncRead.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/trait.AsyncRead.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/trait.AsyncRead.html">../../../tokio/io/trait.AsyncRead.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/trait.AsyncRead.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/async_seek/trait.AsyncSeek.html
Normal file
11
tokio/io/async_seek/trait.AsyncSeek.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/trait.AsyncSeek.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/trait.AsyncSeek.html">../../../tokio/io/trait.AsyncSeek.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/trait.AsyncSeek.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/async_write/trait.AsyncWrite.html
Normal file
11
tokio/io/async_write/trait.AsyncWrite.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/trait.AsyncWrite.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/trait.AsyncWrite.html">../../../tokio/io/trait.AsyncWrite.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/trait.AsyncWrite.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
26
tokio/io/fn.copy.html
Normal file
26
tokio/io/fn.copy.html
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<!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="Asynchronously copies the entire contents of a reader into a writer."><title>copy in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">copy</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#errors" title="Errors">Errors</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">copy</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/util/copy.rs.html#269-279">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn copy<'a, R, W>(reader: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&'a mut R</a>, writer: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&'a mut W</a>) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u64.html">u64</a>><div class="where">where
|
||||
R: <a class="trait" href="trait.AsyncRead.html" title="trait tokio::io::AsyncRead">AsyncRead</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
W: <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Asynchronously copies the entire contents of a reader into a writer.</p>
|
||||
<p>This function returns a future that will continuously read data from
|
||||
<code>reader</code> and then write it into <code>writer</code> in a streaming fashion until
|
||||
<code>reader</code> returns EOF or fails.</p>
|
||||
<p>On success, the total number of bytes that were copied from <code>reader</code> to
|
||||
<code>writer</code> is returned.</p>
|
||||
<p>This is an asynchronous version of <a href="https://doc.rust-lang.org/1.84.1/std/io/copy/fn.copy.html" title="fn std::io::copy::copy"><code>std::io::copy</code></a>.</p>
|
||||
<p>A heap-allocated copy buffer with 8 KB is created to take data from the
|
||||
reader to the writer, check <a href="fn.copy_buf.html" title="fn tokio::io::copy_buf"><code>copy_buf</code></a> if you want an alternative for
|
||||
<a href="trait.AsyncBufRead.html" title="trait tokio::io::AsyncBufRead"><code>AsyncBufRead</code></a>. You can use <code>copy_buf</code> with <a href="struct.BufReader.html" title="struct tokio::io::BufReader"><code>BufReader</code></a> to change the
|
||||
buffer capacity.</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<p>The returned future will return an error immediately if any call to
|
||||
<code>poll_read</code> or <code>poll_write</code> returns an error.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>reader: <span class="kw-2">&</span>[u8] = <span class="string">b"hello"</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>writer: Vec<u8> = <span class="macro">vec!</span>[];
|
||||
|
||||
io::copy(<span class="kw-2">&mut </span>reader, <span class="kw-2">&mut </span>writer).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="string">b"hello"</span>[..], <span class="kw-2">&</span>writer[..]);</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
26
tokio/io/fn.copy_bidirectional.html
Normal file
26
tokio/io/fn.copy_bidirectional.html
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<!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="Copies data in both directions between `a` and `b`."><title>copy_bidirectional in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">copy_<wbr>bidirectional</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#errors" title="Errors">Errors</a></li><li><a href="#return-value" title="Return value">Return value</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">copy_bidirectional</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/util/copy_bidirectional.rs.html#75-87">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn copy_bidirectional<A, B>(
|
||||
a: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&mut A</a>,
|
||||
b: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&mut B</a>,
|
||||
) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><(<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u64.html">u64</a>, <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u64.html">u64</a>)><div class="where">where
|
||||
A: <a class="trait" href="trait.AsyncRead.html" title="trait tokio::io::AsyncRead">AsyncRead</a> + <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
B: <a class="trait" href="trait.AsyncRead.html" title="trait tokio::io::AsyncRead">AsyncRead</a> + <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Copies data in both directions between <code>a</code> and <code>b</code>.</p>
|
||||
<p>This function returns a future that will read from both streams,
|
||||
writing any data read to the opposing stream.
|
||||
This happens in both directions concurrently.</p>
|
||||
<p>If an EOF is observed on one stream, <a href="trait.AsyncWriteExt.html#method.shutdown" title="method tokio::io::AsyncWriteExt::shutdown"><code>shutdown()</code></a> will be invoked on
|
||||
the other, and reading from that stream will stop. Copying of data in
|
||||
the other direction will continue.</p>
|
||||
<p>The future will complete successfully once both directions of communication has been shut down.
|
||||
A direction is shut down when the reader reports EOF,
|
||||
at which point <a href="trait.AsyncWriteExt.html#method.shutdown" title="method tokio::io::AsyncWriteExt::shutdown"><code>shutdown()</code></a> is called on the corresponding writer. When finished,
|
||||
it will return a tuple of the number of bytes copied from a to b
|
||||
and the number of bytes copied from b to a, in that order.</p>
|
||||
<p>It uses two 8 KB buffers for transferring bytes between <code>a</code> and <code>b</code> by default.
|
||||
To set your own buffers sizes use <a href="fn.copy_bidirectional_with_sizes.html" title="fn tokio::io::copy_bidirectional_with_sizes"><code>copy_bidirectional_with_sizes()</code></a>.</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<p>The future will immediately return an error if any IO operation on <code>a</code>
|
||||
or <code>b</code> returns an error. Some data read from either stream may be lost (not
|
||||
written to the other stream) in this case.</p>
|
||||
<h2 id="return-value"><a class="doc-anchor" href="#return-value">§</a>Return value</h2>
|
||||
<p>Returns a tuple of bytes copied <code>a</code> to <code>b</code> and bytes copied <code>b</code> to <code>a</code>.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
11
tokio/io/fn.copy_bidirectional_with_sizes.html
Normal file
11
tokio/io/fn.copy_bidirectional_with_sizes.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!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="Copies data in both directions between `a` and `b` using buffers of the specified size."><title>copy_bidirectional_with_sizes in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">copy_bidirectional_with_sizes</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/util/copy_bidirectional.rs.html#94-111">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn copy_bidirectional_with_sizes<A, B>(
|
||||
a: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&mut A</a>,
|
||||
b: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&mut B</a>,
|
||||
a_to_b_buf_size: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
|
||||
b_to_a_buf_size: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
|
||||
) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><(<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u64.html">u64</a>, <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u64.html">u64</a>)><div class="where">where
|
||||
A: <a class="trait" href="trait.AsyncRead.html" title="trait tokio::io::AsyncRead">AsyncRead</a> + <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
B: <a class="trait" href="trait.AsyncRead.html" title="trait tokio::io::AsyncRead">AsyncRead</a> + <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Copies data in both directions between <code>a</code> and <code>b</code> using buffers of the specified size.</p>
|
||||
<p>This method is the same as the <a href="fn.copy_bidirectional.html" title="fn tokio::io::copy_bidirectional"><code>copy_bidirectional()</code></a>, except that it allows you to set the
|
||||
size of the internal buffers used when copying data.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
28
tokio/io/fn.copy_buf.html
Normal file
28
tokio/io/fn.copy_buf.html
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<!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="Asynchronously copies the entire contents of a reader into a writer."><title>copy_buf in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">copy_<wbr>buf</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#errors" title="Errors">Errors</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">copy_buf</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/util/copy_buf.rs.html#60-70">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn copy_buf<'a, R, W>(
|
||||
reader: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&'a mut R</a>,
|
||||
writer: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&'a mut W</a>,
|
||||
) -> <a class="type" href="https://doc.rust-lang.org/1.84.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u64.html">u64</a>><div class="where">where
|
||||
R: <a class="trait" href="trait.AsyncBufRead.html" title="trait tokio::io::AsyncBufRead">AsyncBufRead</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
W: <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Asynchronously copies the entire contents of a reader into a writer.</p>
|
||||
<p>This function returns a future that will continuously read data from
|
||||
<code>reader</code> and then write it into <code>writer</code> in a streaming fashion until
|
||||
<code>reader</code> returns EOF or fails.</p>
|
||||
<p>On success, the total number of bytes that were copied from <code>reader</code> to
|
||||
<code>writer</code> is returned.</p>
|
||||
<p>This is a <a href="fn.copy.html" title="fn tokio::io::copy"><code>tokio::io::copy</code></a> alternative for <a href="trait.AsyncBufRead.html" title="trait tokio::io::AsyncBufRead"><code>AsyncBufRead</code></a> readers
|
||||
with no extra buffer allocation, since <a href="trait.AsyncBufRead.html" title="trait tokio::io::AsyncBufRead"><code>AsyncBufRead</code></a> allow access
|
||||
to the reader’s inner buffer.</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<p>The returned future will finish with an error will return an error
|
||||
immediately if any call to <code>poll_fill_buf</code> or <code>poll_write</code> returns an
|
||||
error.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>reader: <span class="kw-2">&</span>[u8] = <span class="string">b"hello"</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>writer: Vec<u8> = <span class="macro">vec!</span>[];
|
||||
|
||||
io::copy_buf(<span class="kw-2">&mut </span>reader, <span class="kw-2">&mut </span>writer).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="macro">assert_eq!</span>(<span class="string">b"hello"</span>, <span class="kw-2">&</span>writer[..]);</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
4
tokio/io/fn.duplex.html
Normal file
4
tokio/io/fn.duplex.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<!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="Create a new pair of `DuplexStream`s that act like a pair of connected sockets."><title>duplex in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">duplex</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/util/mem.rs.html#104-118">Source</a> </span></div><pre class="rust item-decl"><code>pub fn duplex(max_buf_size: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>) -> (<a class="struct" href="struct.DuplexStream.html" title="struct tokio::io::DuplexStream">DuplexStream</a>, <a class="struct" href="struct.DuplexStream.html" title="struct tokio::io::DuplexStream">DuplexStream</a>)</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Create a new pair of <code>DuplexStream</code>s that act like a pair of connected sockets.</p>
|
||||
<p>The <code>max_buf_size</code> argument is the maximum amount of bytes that can be
|
||||
written to a side before the write returns <code>Poll::Pending</code>.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
27
tokio/io/fn.empty.html
Normal file
27
tokio/io/fn.empty.html
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<!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="Creates a value that is always at EOF for reads, and ignores all data written."><title>empty in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">empty</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">empty</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/util/empty.rs.html#62-64">Source</a> </span></div><pre class="rust item-decl"><code>pub fn empty() -> <a class="struct" href="struct.Empty.html" title="struct tokio::io::Empty">Empty</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates a value that is always at EOF for reads, and ignores all data written.</p>
|
||||
<p>All writes on the returned instance will return <code>Poll::Ready(Ok(buf.len()))</code>
|
||||
and the contents of the buffer will not be inspected.</p>
|
||||
<p>All reads from the returned instance will return <code>Poll::Ready(Ok(0))</code>.</p>
|
||||
<p>This is an asynchronous version of <a href="https://doc.rust-lang.org/1.84.1/std/io/util/fn.empty.html" title="fn std::io::util::empty"><code>std::io::empty</code></a>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>A slightly sad example of not reading anything into a buffer:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncReadExt};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>buffer = String::new();
|
||||
io::empty().read_to_string(<span class="kw-2">&mut </span>buffer).<span class="kw">await</span>.unwrap();
|
||||
<span class="macro">assert!</span>(buffer.is_empty());
|
||||
}</code></pre></div>
|
||||
<p>A convoluted way of getting the length of a buffer:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span>buffer = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>];
|
||||
<span class="kw">let </span>num_bytes = io::empty().write(<span class="kw-2">&</span>buffer).<span class="kw">await</span>.unwrap();
|
||||
<span class="macro">assert_eq!</span>(num_bytes, <span class="number">5</span>);
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
5
tokio/io/fn.join.html
Normal file
5
tokio/io/fn.join.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<!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="Join two values implementing `AsyncRead` and `AsyncWrite` into a single handle."><title>join in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">join</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/join.rs.html#11-17">Source</a> </span></div><pre class="rust item-decl"><code>pub fn join<R, W>(reader: R, writer: W) -> <a class="struct" href="struct.Join.html" title="struct tokio::io::Join">Join</a><R, W><div class="where">where
|
||||
R: <a class="trait" href="trait.AsyncRead.html" title="trait tokio::io::AsyncRead">AsyncRead</a>,
|
||||
W: <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a>,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Join two values implementing <code>AsyncRead</code> and <code>AsyncWrite</code> into a
|
||||
single handle.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
14
tokio/io/fn.repeat.html
Normal file
14
tokio/io/fn.repeat.html
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<!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="Creates an instance of an async reader that infinitely repeats one byte."><title>repeat in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">repeat</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">repeat</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/util/repeat.rs.html#45-47">Source</a> </span></div><pre class="rust item-decl"><code>pub fn repeat(byte: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u8.html">u8</a>) -> <a class="struct" href="struct.Repeat.html" title="struct tokio::io::Repeat">Repeat</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates an instance of an async reader that infinitely repeats one byte.</p>
|
||||
<p>All reads from this reader will succeed by filling the specified buffer with
|
||||
the given byte.</p>
|
||||
<p>This is an asynchronous version of <a href="https://doc.rust-lang.org/1.84.1/std/io/util/fn.repeat.html" title="fn std::io::util::repeat"><code>std::io::repeat</code></a>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncReadExt};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>buffer = [<span class="number">0</span>; <span class="number">3</span>];
|
||||
io::repeat(<span class="number">0b101</span>).read_exact(<span class="kw-2">&mut </span>buffer).<span class="kw">await</span>.unwrap();
|
||||
<span class="macro">assert_eq!</span>(buffer, [<span class="number">0b101</span>, <span class="number">0b101</span>, <span class="number">0b101</span>]);
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
19
tokio/io/fn.simplex.html
Normal file
19
tokio/io/fn.simplex.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<!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="Creates unidirectional buffer that acts like in memory pipe."><title>simplex in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">simplex</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#unify-reader-and-writer" title="Unify reader and writer">Unify reader and writer</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">simplex</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/util/mem.rs.html#211-213">Source</a> </span></div><pre class="rust item-decl"><code>pub fn simplex(
|
||||
max_buf_size: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
|
||||
) -> (<a class="struct" href="struct.ReadHalf.html" title="struct tokio::io::ReadHalf">ReadHalf</a><<a class="struct" href="struct.SimplexStream.html" title="struct tokio::io::SimplexStream">SimplexStream</a>>, <a class="struct" href="struct.WriteHalf.html" title="struct tokio::io::WriteHalf">WriteHalf</a><<a class="struct" href="struct.SimplexStream.html" title="struct tokio::io::SimplexStream">SimplexStream</a>>)</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates unidirectional buffer that acts like in memory pipe.</p>
|
||||
<p>The <code>max_buf_size</code> argument is the maximum amount of bytes that can be
|
||||
written to a buffer before the it returns <code>Poll::Pending</code>.</p>
|
||||
<h2 id="unify-reader-and-writer"><a class="doc-anchor" href="#unify-reader-and-writer">§</a>Unify reader and writer</h2>
|
||||
<p>The reader and writer half can be unified into a single structure
|
||||
of <code>SimplexStream</code> that supports both reading and writing or
|
||||
the <code>SimplexStream</code> can be already created as unified structure
|
||||
using <a href="struct.SimplexStream.html#method.new_unsplit" title="associated function tokio::io::SimplexStream::new_unsplit"><code>SimplexStream::new_unsplit()</code></a>.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>(writer, reader) = tokio::io::simplex(<span class="number">64</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>simplex_stream = writer.unsplit(reader);
|
||||
simplex_stream.write_all(<span class="string">b"hello"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0u8</span>; <span class="number">5</span>];
|
||||
simplex_stream.read_exact(<span class="kw-2">&mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>buf, <span class="string">b"hello"</span>);</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
17
tokio/io/fn.sink.html
Normal file
17
tokio/io/fn.sink.html
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<!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="Creates an instance of an async writer which will successfully consume all data."><title>sink in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">sink</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">sink</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/util/sink.rs.html#48-50">Source</a> </span></div><pre class="rust item-decl"><code>pub fn sink() -> <a class="struct" href="struct.Sink.html" title="struct tokio::io::Sink">Sink</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates an instance of an async writer which will successfully consume all
|
||||
data.</p>
|
||||
<p>All calls to <a href="trait.AsyncWrite.html#tymethod.poll_write" title="method tokio::io::AsyncWrite::poll_write"><code>poll_write</code></a> on the returned instance will return
|
||||
<code>Poll::Ready(Ok(buf.len()))</code> and the contents of the buffer will not be
|
||||
inspected.</p>
|
||||
<p>This is an asynchronous version of <a href="https://doc.rust-lang.org/1.84.1/std/io/util/fn.sink.html" title="fn std::io::util::sink"><code>std::io::sink</code></a>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||||
<span class="kw">let </span>buffer = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>];
|
||||
<span class="kw">let </span>num_bytes = io::sink().write(<span class="kw-2">&</span>buffer).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">assert_eq!</span>(num_bytes, <span class="number">5</span>);
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
6
tokio/io/fn.split.html
Normal file
6
tokio/io/fn.split.html
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<!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="Splits a single value implementing `AsyncRead + AsyncWrite` into separate `AsyncRead` and `AsyncWrite` handles."><title>split in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">split</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/split.rs.html#32-50">Source</a> </span></div><pre class="rust item-decl"><code>pub fn split<T>(stream: T) -> (<a class="struct" href="struct.ReadHalf.html" title="struct tokio::io::ReadHalf">ReadHalf</a><T>, <a class="struct" href="struct.WriteHalf.html" title="struct tokio::io::WriteHalf">WriteHalf</a><T>)<div class="where">where
|
||||
T: <a class="trait" href="trait.AsyncRead.html" title="trait tokio::io::AsyncRead">AsyncRead</a> + <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a>,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Splits a single value implementing <code>AsyncRead + AsyncWrite</code> into separate
|
||||
<code>AsyncRead</code> and <code>AsyncWrite</code> handles.</p>
|
||||
<p>To restore this read/write object from its <code>ReadHalf</code> and
|
||||
<code>WriteHalf</code> use <a href="struct.ReadHalf.html#method.unsplit" title="method tokio::io::ReadHalf::unsplit"><code>unsplit</code></a>.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
18
tokio/io/fn.stderr.html
Normal file
18
tokio/io/fn.stderr.html
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<!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="Constructs a new handle to the standard error of the current process."><title>stderr in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">stderr</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">stderr</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/stderr.rs.html#68-73">Source</a> </span></div><pre class="rust item-decl"><code>pub fn stderr() -> <a class="struct" href="struct.Stderr.html" title="struct tokio::io::Stderr">Stderr</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Constructs a new handle to the standard error of the current process.</p>
|
||||
<p>The returned handle allows writing to standard error from the within the
|
||||
Tokio runtime.</p>
|
||||
<p>Concurrent writes to stderr must be executed with care: Only individual
|
||||
writes to this <a href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite"><code>AsyncWrite</code></a> are guaranteed to be intact. In particular
|
||||
you should be aware that writes using <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>write_all</code></a> are not guaranteed
|
||||
to occur as a single write, so multiple threads writing data with
|
||||
<a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>write_all</code></a> may result in interleaved output.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>stderr = io::stderr();
|
||||
stderr.write_all(<span class="string">b"Print some error here."</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
9
tokio/io/fn.stdin.html
Normal file
9
tokio/io/fn.stdin.html
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<!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="Constructs a new handle to the standard input of the current process."><title>stdin in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">stdin</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/stdin.rs.html#43-48">Source</a> </span></div><pre class="rust item-decl"><code>pub fn stdin() -> <a class="struct" href="struct.Stdin.html" title="struct tokio::io::Stdin">Stdin</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Constructs a new handle to the standard input of the current process.</p>
|
||||
<p>This handle is best used for non-interactive uses, such as when a file
|
||||
is piped into the application. For technical reasons, <code>stdin</code> is
|
||||
implemented by using an ordinary blocking read on a separate thread, and
|
||||
it is impossible to cancel that read. This can make shutdown of the
|
||||
runtime hang until the user presses enter.</p>
|
||||
<p>For interactive uses, it is recommended to spawn a thread dedicated to
|
||||
user input and use blocking IO directly in that thread.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
40
tokio/io/fn.stdout.html
Normal file
40
tokio/io/fn.stdout.html
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<!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="Constructs a new handle to the standard output of the current process."><title>stdout in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.42.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">stdout</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></span><h1>Function <span class="fn">stdout</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/stdout.rs.html#117-122">Source</a> </span></div><pre class="rust item-decl"><code>pub fn stdout() -> <a class="struct" href="struct.Stdout.html" title="struct tokio::io::Stdout">Stdout</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Constructs a new handle to the standard output of the current process.</p>
|
||||
<p>The returned handle allows writing to standard out from the within the
|
||||
Tokio runtime.</p>
|
||||
<p>Concurrent writes to stdout must be executed with care: Only individual
|
||||
writes to this <a href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite"><code>AsyncWrite</code></a> are guaranteed to be intact. In particular
|
||||
you should be aware that writes using <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>write_all</code></a> are not guaranteed
|
||||
to occur as a single write, so multiple threads writing data with
|
||||
<a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>write_all</code></a> may result in interleaved output.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>stdout = io::stdout();
|
||||
stdout.write_all(<span class="string">b"Hello world!"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div>
|
||||
<p>The following is an example of using <code>stdio</code> with loop.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span>messages = <span class="macro">vec!</span>[<span class="string">"hello"</span>, <span class="string">" world\n"</span>];
|
||||
|
||||
<span class="comment">// When you use `stdio` in a loop, it is recommended to create
|
||||
// a single `stdio` instance outside the loop and call a write
|
||||
// operation against that instance on each loop.
|
||||
//
|
||||
// Repeatedly creating `stdout` instances inside the loop and
|
||||
// writing to that handle could result in mangled output since
|
||||
// each write operation is handled by a different blocking thread.
|
||||
</span><span class="kw">let </span><span class="kw-2">mut </span>stdout = io::stdout();
|
||||
|
||||
<span class="kw">for </span>message <span class="kw">in </span><span class="kw-2">&</span>messages {
|
||||
stdout.write_all(message.as_bytes()).<span class="kw">await</span>.unwrap();
|
||||
stdout.flush().<span class="kw">await</span>.unwrap();
|
||||
}
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
128
tokio/io/index.html
Normal file
128
tokio/io/index.html
Normal file
File diff suppressed because one or more lines are too long
11
tokio/io/interest/struct.Interest.html
Normal file
11
tokio/io/interest/struct.Interest.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/struct.Interest.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/struct.Interest.html">../../../tokio/io/struct.Interest.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/struct.Interest.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/join/fn.join.html
Normal file
11
tokio/io/join/fn.join.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/fn.join.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/fn.join.html">../../../tokio/io/fn.join.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/fn.join.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/join/struct.Join.html
Normal file
11
tokio/io/join/struct.Join.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/struct.Join.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/struct.Join.html">../../../tokio/io/struct.Join.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/struct.Join.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/read_buf/struct.ReadBuf.html
Normal file
11
tokio/io/read_buf/struct.ReadBuf.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/struct.ReadBuf.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/struct.ReadBuf.html">../../../tokio/io/struct.ReadBuf.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/struct.ReadBuf.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/ready/struct.Ready.html
Normal file
11
tokio/io/ready/struct.Ready.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/struct.Ready.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/struct.Ready.html">../../../tokio/io/struct.Ready.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/struct.Ready.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
1
tokio/io/sidebar-items.js
Normal file
1
tokio/io/sidebar-items.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
window.SIDEBAR_ITEMS = {"fn":["copy","copy_bidirectional","copy_bidirectional_with_sizes","copy_buf","duplex","empty","join","repeat","simplex","sink","split","stderr","stdin","stdout"],"mod":["unix"],"struct":["BufReader","BufStream","BufWriter","DuplexStream","Empty","Interest","Join","Lines","ReadBuf","ReadHalf","Ready","Repeat","SimplexStream","Sink","Split","Stderr","Stdin","Stdout","Take","WriteHalf"],"trait":["AsyncBufRead","AsyncBufReadExt","AsyncRead","AsyncReadExt","AsyncSeek","AsyncSeekExt","AsyncWrite","AsyncWriteExt"]};
|
||||
11
tokio/io/split/fn.split.html
Normal file
11
tokio/io/split/fn.split.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/fn.split.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/fn.split.html">../../../tokio/io/fn.split.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/fn.split.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/split/struct.ReadHalf.html
Normal file
11
tokio/io/split/struct.ReadHalf.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/struct.ReadHalf.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/struct.ReadHalf.html">../../../tokio/io/struct.ReadHalf.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/struct.ReadHalf.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/split/struct.WriteHalf.html
Normal file
11
tokio/io/split/struct.WriteHalf.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/struct.WriteHalf.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/struct.WriteHalf.html">../../../tokio/io/struct.WriteHalf.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/struct.WriteHalf.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/stderr/fn.stderr.html
Normal file
11
tokio/io/stderr/fn.stderr.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/fn.stderr.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/fn.stderr.html">../../../tokio/io/fn.stderr.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/fn.stderr.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/stderr/struct.Stderr.html
Normal file
11
tokio/io/stderr/struct.Stderr.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/struct.Stderr.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/struct.Stderr.html">../../../tokio/io/struct.Stderr.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/struct.Stderr.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/stdin/fn.stdin.html
Normal file
11
tokio/io/stdin/fn.stdin.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/fn.stdin.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/fn.stdin.html">../../../tokio/io/fn.stdin.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/fn.stdin.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/stdin/struct.Stdin.html
Normal file
11
tokio/io/stdin/struct.Stdin.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/struct.Stdin.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/struct.Stdin.html">../../../tokio/io/struct.Stdin.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/struct.Stdin.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/stdout/fn.stdout.html
Normal file
11
tokio/io/stdout/fn.stdout.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/fn.stdout.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/fn.stdout.html">../../../tokio/io/fn.stdout.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/fn.stdout.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/io/stdout/struct.Stdout.html
Normal file
11
tokio/io/stdout/struct.Stdout.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/io/struct.Stdout.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/io/struct.Stdout.html">../../../tokio/io/struct.Stdout.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/io/struct.Stdout.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
221
tokio/io/struct.BufReader.html
Normal file
221
tokio/io/struct.BufReader.html
Normal file
File diff suppressed because one or more lines are too long
219
tokio/io/struct.BufStream.html
Normal file
219
tokio/io/struct.BufStream.html
Normal file
File diff suppressed because one or more lines are too long
208
tokio/io/struct.BufWriter.html
Normal file
208
tokio/io/struct.BufWriter.html
Normal file
File diff suppressed because one or more lines are too long
169
tokio/io/struct.DuplexStream.html
Normal file
169
tokio/io/struct.DuplexStream.html
Normal file
File diff suppressed because one or more lines are too long
187
tokio/io/struct.Empty.html
Normal file
187
tokio/io/struct.Empty.html
Normal file
File diff suppressed because one or more lines are too long
87
tokio/io/struct.Interest.html
Normal file
87
tokio/io/struct.Interest.html
Normal file
File diff suppressed because one or more lines are too long
199
tokio/io/struct.Join.html
Normal file
199
tokio/io/struct.Join.html
Normal file
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue