mirror of
https://github.com/NotAShelf/mpvrc.git
synced 2026-04-18 00:38:14 +00:00
deploy: de38ae62916547ad097c066f94a32e9ba7790eeb
This commit is contained in:
commit
9a86359447
28502 changed files with 1261284 additions and 0 deletions
11
tokio/task/blocking/fn.block_in_place.html
Normal file
11
tokio/task/blocking/fn.block_in_place.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/fn.block_in_place.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/fn.block_in_place.html">../../../tokio/task/fn.block_in_place.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/fn.block_in_place.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/task/blocking/fn.spawn_blocking.html
Normal file
11
tokio/task/blocking/fn.spawn_blocking.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/fn.spawn_blocking.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/fn.spawn_blocking.html">../../../tokio/task/fn.spawn_blocking.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/fn.spawn_blocking.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/task/consume_budget/fn.consume_budget.html
Normal file
11
tokio/task/consume_budget/fn.consume_budget.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/fn.consume_budget.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/fn.consume_budget.html">../../../tokio/task/fn.consume_budget.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/fn.consume_budget.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
46
tokio/task/fn.block_in_place.html
Normal file
46
tokio/task/fn.block_in_place.html
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<!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="Runs the provided blocking function on the current thread without blocking the executor."><title>block_in_place in tokio::task - 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="#">block_<wbr>in_<wbr>place</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li><li><a href="#panics" title="Panics">Panics</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>task</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">task</a></span><h1>Function <span class="fn">block_in_place</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/task/blocking.rs.html#74-79">Source</a> </span></div><pre class="rust item-decl"><code>pub fn block_in_place<F, R>(f: F) -> R<div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>() -> R,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Runs the provided blocking function on the current thread without
|
||||
blocking the executor.</p>
|
||||
<p>In general, issuing a blocking call or performing a lot of compute in a
|
||||
future without yielding is problematic, as it may prevent the executor
|
||||
from driving other tasks forward. Calling this function informs the
|
||||
executor that the currently executing task is about to block the thread,
|
||||
so the executor is able to hand off any other tasks it has to a new
|
||||
worker thread before that happens. See the <a href="../index.html#cpu-bound-tasks-and-blocking-code">CPU-bound tasks and blocking
|
||||
code</a> section for more information.</p>
|
||||
<p>Be aware that although this function avoids starving other independently
|
||||
spawned tasks, any other code running concurrently in the same task will
|
||||
be suspended during the call to <code>block_in_place</code>. This can happen e.g.
|
||||
when using the <a href="../macro.join.html" title="macro tokio::join"><code>join!</code></a> macro. To avoid this issue, use
|
||||
<a href="fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a> instead of <code>block_in_place</code>.</p>
|
||||
<p>Note that this function cannot be used within a <a href="../runtime/struct.Builder.html#method.new_current_thread" title="associated function tokio::runtime::Builder::new_current_thread"><code>current_thread</code></a> runtime
|
||||
because in this case there are no other worker threads to hand off tasks
|
||||
to. On the other hand, calling the function outside a runtime is
|
||||
allowed. In this case, <code>block_in_place</code> just calls the provided closure
|
||||
normally.</p>
|
||||
<p>Code running behind <code>block_in_place</code> cannot be cancelled. When you shut
|
||||
down the executor, it will wait indefinitely for all blocking operations
|
||||
to finish. You can use <a href="../runtime/struct.Runtime.html#method.shutdown_timeout" title="method tokio::runtime::Runtime::shutdown_timeout"><code>shutdown_timeout</code></a> to stop waiting for them
|
||||
after a certain timeout. Be aware that this will still not cancel the
|
||||
tasks — they are simply allowed to keep running after the method
|
||||
returns.</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::task;
|
||||
|
||||
task::block_in_place(<span class="kw">move </span>|| {
|
||||
<span class="comment">// do some compute-heavy work or call synchronous code
|
||||
</span>});</code></pre></div>
|
||||
<p>Code running inside <code>block_in_place</code> may use <code>block_on</code> to reenter the
|
||||
async context.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
<span class="kw">use </span>tokio::runtime::Handle;
|
||||
|
||||
task::block_in_place(<span class="kw">move </span>|| {
|
||||
Handle::current().block_on(<span class="kw">async move </span>{
|
||||
<span class="comment">// do something async
|
||||
</span>});
|
||||
});</code></pre></div>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This function panics if called from a <a href="../runtime/struct.Builder.html#method.new_current_thread" title="associated function tokio::runtime::Builder::new_current_thread"><code>current_thread</code></a> runtime.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
19
tokio/task/fn.consume_budget.html
Normal file
19
tokio/task/fn.consume_budget.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="Consumes a unit of budget and returns the execution back to the Tokio runtime if the task’s coop budget was exhausted."><title>consume_budget in tokio::task - 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="#">consume_<wbr>budget</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>task</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">task</a></span><h1>Function <span class="fn">consume_budget</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/task/consume_budget.rs.html#27-41">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn consume_budget()</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Consumes a unit of budget and returns the execution back to the Tokio
|
||||
runtime <em>if</em> the task’s coop budget was exhausted.</p>
|
||||
<p>The task will only yield if its entire coop budget has been exhausted.
|
||||
This function can be used in order to insert optional yield points into long
|
||||
computations that do not use Tokio resources like sockets or semaphores,
|
||||
without redundantly yielding to the runtime each time.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>Make sure that a function which returns a sum of (potentially lots of)
|
||||
iterated values is cooperative.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>sum_iterator(input: <span class="kw-2">&mut </span><span class="kw">impl </span>std::iter::Iterator<Item=i64>) -> i64 {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>sum: i64 = <span class="number">0</span>;
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(i) = input.next() {
|
||||
sum += i;
|
||||
tokio::task::consume_budget().<span class="kw">await
|
||||
</span>}
|
||||
sum
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
7
tokio/task/fn.id.html
Normal file
7
tokio/task/fn.id.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<!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 `Id` of the currently running task."><title>id in tokio::task - 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="#">id</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#panics" title="Panics">Panics</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>task</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">task</a></span><h1>Function <span class="fn">id</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/runtime/task/id.rs.html#33-35">Source</a> </span></div><pre class="rust item-decl"><code>pub fn id() -> <a class="struct" href="struct.Id.html" title="struct tokio::task::Id">Id</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Returns the <a href="struct.Id.html" title="struct tokio::task::Id"><code>Id</code></a> of the currently running task.</p>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This function panics if called from outside a task. Please note that calls
|
||||
to <code>block_on</code> do not have task IDs, so the method will panic if called from
|
||||
within a call to <code>block_on</code>. For a version of this function that doesn’t
|
||||
panic, see <a href="fn.try_id.html" title="fn tokio::task::try_id"><code>task::try_id()</code></a>.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
123
tokio/task/fn.spawn.html
Normal file
123
tokio/task/fn.spawn.html
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
<!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="Spawns a new asynchronous task, returning a `JoinHandle` for it."><title>spawn in tokio::task - 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="#">spawn</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li><li><a href="#panics" title="Panics">Panics</a></li><li><a href="#using-send-values-from-a-task" title="Using `!Send` values from a task">Using <code>!Send</code> values from a task</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>task</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">task</a></span><h1>Function <span class="fn">spawn</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/task/spawn.rs.html#166-177">Source</a> </span></div><pre class="rust item-decl"><code>pub fn spawn<F>(future: F) -> <a class="struct" href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle">JoinHandle</a><F::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>> <a href="#" class="tooltip" data-notable-ty="JoinHandle<F::Output>">ⓘ</a><div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static,
|
||||
F::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Spawns a new asynchronous task, returning a
|
||||
<a href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle"><code>JoinHandle</code></a> for it.</p>
|
||||
<p>The provided future will start running in the background immediately
|
||||
when <code>spawn</code> is called, even if you don’t await the returned
|
||||
<code>JoinHandle</code>.</p>
|
||||
<p>Spawning a task enables the task to execute concurrently to other tasks. The
|
||||
spawned task may execute on the current thread, or it may be sent to a
|
||||
different thread to be executed. The specifics depend on the current
|
||||
<a href="../runtime/struct.Runtime.html" title="struct tokio::runtime::Runtime"><code>Runtime</code></a> configuration.</p>
|
||||
<p>It is guaranteed that spawn will not synchronously poll the task being spawned.
|
||||
This means that calling spawn while holding a lock does not pose a risk of
|
||||
deadlocking with the spawned task.</p>
|
||||
<p>There is no guarantee that a spawned task will execute to completion.
|
||||
When a runtime is shutdown, all outstanding tasks are dropped,
|
||||
regardless of the lifecycle of that task.</p>
|
||||
<p>This function must be called from the context of a Tokio runtime. Tasks running on
|
||||
the Tokio runtime are always inside its context, but you can also enter the context
|
||||
using the <a href="../runtime/struct.Runtime.html#method.enter" title="method tokio::runtime::Runtime::enter"><code>Runtime::enter</code></a> method.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>In this example, a server is started and <code>spawn</code> is used to start a new task
|
||||
that processes each received connection.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::{TcpListener, TcpStream};
|
||||
|
||||
<span class="kw">use </span>std::io;
|
||||
|
||||
<span class="kw">async fn </span>process(socket: TcpStream) {
|
||||
<span class="comment">// ...
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||||
<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>(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="comment">// Process each socket concurrently.
|
||||
</span>process(socket).<span class="kw">await
|
||||
</span>});
|
||||
}
|
||||
}</code></pre></div>
|
||||
<p>To run multiple tasks in parallel and receive their results, join
|
||||
handles can be stored in a vector.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>my_background_op(id: i32) -> String {
|
||||
<span class="kw">let </span>s = <span class="macro">format!</span>(<span class="string">"Starting background task {}."</span>, id);
|
||||
<span class="macro">println!</span>(<span class="string">"{}"</span>, s);
|
||||
s
|
||||
}
|
||||
|
||||
<span class="kw">let </span>ops = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>tasks = Vec::with_capacity(ops.len());
|
||||
<span class="kw">for </span>op <span class="kw">in </span>ops {
|
||||
<span class="comment">// This call will make them start running in the background
|
||||
// immediately.
|
||||
</span>tasks.push(tokio::spawn(my_background_op(op)));
|
||||
}
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>outputs = Vec::with_capacity(tasks.len());
|
||||
<span class="kw">for </span>task <span class="kw">in </span>tasks {
|
||||
outputs.push(task.<span class="kw">await</span>.unwrap());
|
||||
}
|
||||
<span class="macro">println!</span>(<span class="string">"{:?}"</span>, outputs);</code></pre></div>
|
||||
<p>This example pushes the tasks to <code>outputs</code> in the order they were
|
||||
started in. If you do not care about the ordering of the outputs, then
|
||||
you can also use a <a href="struct.JoinSet.html" title="struct tokio::task::JoinSet"><code>JoinSet</code></a>.</p>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>Panics if called from <strong>outside</strong> of the Tokio runtime.</p>
|
||||
<h2 id="using-send-values-from-a-task"><a class="doc-anchor" href="#using-send-values-from-a-task">§</a>Using <code>!Send</code> values from a task</h2>
|
||||
<p>The task supplied to <code>spawn</code> must implement <code>Send</code>. However, it is
|
||||
possible to <strong>use</strong> <code>!Send</code> values from the task as long as they only
|
||||
exist between calls to <code>.await</code>.</p>
|
||||
<p>For example, this will work:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
|
||||
<span class="kw">use </span>std::rc::Rc;
|
||||
|
||||
<span class="kw">fn </span>use_rc(rc: Rc<()>) {
|
||||
<span class="comment">// Do stuff w/ rc
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
tokio::spawn(<span class="kw">async </span>{
|
||||
<span class="comment">// Force the `Rc` to stay in a scope with no `.await`
|
||||
</span>{
|
||||
<span class="kw">let </span>rc = Rc::new(());
|
||||
use_rc(rc.clone());
|
||||
}
|
||||
|
||||
task::yield_now().<span class="kw">await</span>;
|
||||
}).<span class="kw">await</span>.unwrap();
|
||||
}</code></pre></div>
|
||||
<p>This will <strong>not</strong> work:</p>
|
||||
|
||||
<div class="example-wrap compile_fail"><a href="#" class="tooltip" title="This example deliberately fails to compile">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
|
||||
<span class="kw">use </span>std::rc::Rc;
|
||||
|
||||
<span class="kw">fn </span>use_rc(rc: Rc<()>) {
|
||||
<span class="comment">// Do stuff w/ rc
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
tokio::spawn(<span class="kw">async </span>{
|
||||
<span class="kw">let </span>rc = Rc::new(());
|
||||
|
||||
task::yield_now().<span class="kw">await</span>;
|
||||
|
||||
use_rc(rc.clone());
|
||||
}).<span class="kw">await</span>.unwrap();
|
||||
}</code></pre></div>
|
||||
<p>Holding on to a <code>!Send</code> value across calls to <code>.await</code> will result in
|
||||
an unfriendly compile error message similar to:</p>
|
||||
<div class="example-wrap"><pre class="language-text"><code>`[... some type ...]` cannot be sent between threads safely</code></pre></div>
|
||||
<p>or:</p>
|
||||
<div class="example-wrap"><pre class="language-text"><code>error[E0391]: cycle detected when processing `main`</code></pre></div></div></details><script type="text/json" id="notable-traits-data">{"JoinHandle<F::Output>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.JoinHandle.html\" title=\"struct tokio::task::JoinHandle\">JoinHandle</a><T></code></h3><pre><code><div class=\"where\">impl<T> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"struct.JoinHandle.html\" title=\"struct tokio::task::JoinHandle\">JoinHandle</a><T></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</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><T, <a class=\"struct\" href=\"struct.JoinError.html\" title=\"struct tokio::task::JoinError\">JoinError</a>>;</div>"}</script></section></div></main></body></html>
|
||||
86
tokio/task/fn.spawn_blocking.html
Normal file
86
tokio/task/fn.spawn_blocking.html
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<!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="Runs the provided closure on a thread where blocking is acceptable."><title>spawn_blocking in tokio::task - 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="#">spawn_<wbr>blocking</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#related-apis-and-patterns-for-bridging-asynchronous-and-blocking-code" title="Related APIs and patterns for bridging asynchronous and blocking code">Related APIs and patterns for bridging asynchronous and blocking code</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>task</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">task</a></span><h1>Function <span class="fn">spawn_blocking</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/task/blocking.rs.html#202-208">Source</a> </span></div><pre class="rust item-decl"><code>pub fn spawn_blocking<F, R>(f: F) -> <a class="struct" href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle">JoinHandle</a><R> <a href="#" class="tooltip" data-notable-ty="JoinHandle<R>">ⓘ</a><div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>() -> R + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static,
|
||||
R: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Runs the provided closure on a thread where blocking is acceptable.</p>
|
||||
<p>In general, issuing a blocking call or performing a lot of compute in a
|
||||
future without yielding is problematic, as it may prevent the executor from
|
||||
driving other futures forward. This function runs the provided closure on a
|
||||
thread dedicated to blocking operations. See the <a href="../index.html#cpu-bound-tasks-and-blocking-code">CPU-bound tasks and
|
||||
blocking code</a> section for more information.</p>
|
||||
<p>Tokio will spawn more blocking threads when they are requested through this
|
||||
function until the upper limit configured on the <a href="../runtime/struct.Builder.html" title="struct tokio::runtime::Builder"><code>Builder</code></a> is reached.
|
||||
After reaching the upper limit, the tasks are put in a queue.
|
||||
The thread limit is very large by default, because <code>spawn_blocking</code> is often
|
||||
used for various kinds of IO operations that cannot be performed
|
||||
asynchronously. When you run CPU-bound code using <code>spawn_blocking</code>, you
|
||||
should keep this large upper limit in mind. When running many CPU-bound
|
||||
computations, a semaphore or some other synchronization primitive should be
|
||||
used to limit the number of computation executed in parallel. Specialized
|
||||
CPU-bound executors, such as <a href="https://docs.rs/rayon">rayon</a>, may also be a good fit.</p>
|
||||
<p>This function is intended for non-async operations that eventually finish on
|
||||
their own. If you want to spawn an ordinary thread, you should use
|
||||
<a href="https://doc.rust-lang.org/1.84.1/std/thread/fn.spawn.html" title="fn std::thread::spawn"><code>thread::spawn</code></a> instead.</p>
|
||||
<p>Be aware that tasks spawned using <code>spawn_blocking</code> cannot be aborted
|
||||
because they are not async. If you call <a href="struct.JoinHandle.html#method.abort" title="method tokio::task::JoinHandle::abort"><code>abort</code></a> on a <code>spawn_blocking</code>
|
||||
task, then this <em>will not have any effect</em>, and the task will continue
|
||||
running normally. The exception is if the task has not started running
|
||||
yet; in that case, calling <code>abort</code> may prevent the task from starting.</p>
|
||||
<p>When you shut down the executor, it will wait indefinitely for all blocking operations to
|
||||
finish. You can use <a href="../runtime/struct.Runtime.html#method.shutdown_timeout" title="method tokio::runtime::Runtime::shutdown_timeout"><code>shutdown_timeout</code></a> to stop waiting for them after a
|
||||
certain timeout. Be aware that this will still not cancel the tasks — they
|
||||
are simply allowed to keep running after the method returns. It is possible
|
||||
for a blocking task to be cancelled if it has not yet started running, but this
|
||||
is not guaranteed.</p>
|
||||
<p>Note that if you are using the single threaded runtime, this function will
|
||||
still spawn additional threads for blocking operations. The current-thread
|
||||
scheduler’s single thread is only used for asynchronous code.</p>
|
||||
<h2 id="related-apis-and-patterns-for-bridging-asynchronous-and-blocking-code"><a class="doc-anchor" href="#related-apis-and-patterns-for-bridging-asynchronous-and-blocking-code">§</a>Related APIs and patterns for bridging asynchronous and blocking code</h2>
|
||||
<p>In simple cases, it is sufficient to have the closure accept input
|
||||
parameters at creation time and return a single value (or struct/tuple, etc.).</p>
|
||||
<p>For more complex situations in which it is desirable to stream data to or from
|
||||
the synchronous context, the <a href="../sync/mpsc/index.html" title="mod tokio::sync::mpsc"><code>mpsc channel</code></a> has <code>blocking_send</code> and
|
||||
<code>blocking_recv</code> methods for use in non-async code such as the thread created
|
||||
by <code>spawn_blocking</code>.</p>
|
||||
<p>Another option is <a href="https://docs.rs/tokio-util/latest/tokio_util/io/struct.SyncIoBridge.html"><code>SyncIoBridge</code></a> for cases where the synchronous context
|
||||
is operating on byte streams. For example, you might use an asynchronous
|
||||
HTTP client such as <a href="https://docs.rs/hyper">hyper</a> to fetch data, but perform complex parsing
|
||||
of the payload body using a library written for synchronous I/O.</p>
|
||||
<p>Finally, see also <a href="https://tokio.rs/tokio/topics/bridging">Bridging with sync code</a> for discussions
|
||||
around the opposite case of using Tokio as part of a larger synchronous
|
||||
codebase.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>Pass an input value and receive result of computation:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
|
||||
<span class="comment">// Initial input
|
||||
</span><span class="kw">let </span><span class="kw-2">mut </span>v = <span class="string">"Hello, "</span>.to_string();
|
||||
<span class="kw">let </span>res = task::spawn_blocking(<span class="kw">move </span>|| {
|
||||
<span class="comment">// Stand-in for compute-heavy work or using synchronous APIs
|
||||
</span>v.push_str(<span class="string">"world"</span>);
|
||||
<span class="comment">// Pass ownership of the value back to the asynchronous context
|
||||
</span>v
|
||||
}).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// `res` is the value returned from the thread
|
||||
</span><span class="macro">assert_eq!</span>(res.as_str(), <span class="string">"Hello, world"</span>);</code></pre></div>
|
||||
<p>Use a channel:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
<span class="kw">use </span>tokio::sync::mpsc;
|
||||
|
||||
<span class="kw">let </span>(tx, <span class="kw-2">mut </span>rx) = mpsc::channel(<span class="number">2</span>);
|
||||
<span class="kw">let </span>start = <span class="number">5</span>;
|
||||
<span class="kw">let </span>worker = task::spawn_blocking(<span class="kw">move </span>|| {
|
||||
<span class="kw">for </span>x <span class="kw">in </span><span class="number">0</span>..<span class="number">10 </span>{
|
||||
<span class="comment">// Stand in for complex computation
|
||||
</span>tx.blocking_send(start + x).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>acc = <span class="number">0</span>;
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(v) = rx.recv().<span class="kw">await </span>{
|
||||
acc += v;
|
||||
}
|
||||
<span class="macro">assert_eq!</span>(acc, <span class="number">95</span>);
|
||||
worker.<span class="kw">await</span>.unwrap();</code></pre></div>
|
||||
</div></details><script type="text/json" id="notable-traits-data">{"JoinHandle<R>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.JoinHandle.html\" title=\"struct tokio::task::JoinHandle\">JoinHandle</a><T></code></h3><pre><code><div class=\"where\">impl<T> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"struct.JoinHandle.html\" title=\"struct tokio::task::JoinHandle\">JoinHandle</a><T></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</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><T, <a class=\"struct\" href=\"struct.JoinError.html\" title=\"struct tokio::task::JoinError\">JoinError</a>>;</div>"}</script></section></div></main></body></html>
|
||||
32
tokio/task/fn.spawn_local.html
Normal file
32
tokio/task/fn.spawn_local.html
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<!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="Spawns a `!Send` future on the current `LocalSet` or `LocalRuntime`."><title>spawn_local in tokio::task - 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="#">spawn_<wbr>local</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#panics" title="Panics">Panics</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>task</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">task</a></span><h1>Function <span class="fn">spawn_local</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/task/local.rs.html#368-379">Source</a> </span></div><pre class="rust item-decl"><code>pub fn spawn_local<F>(future: F) -> <a class="struct" href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle">JoinHandle</a><F::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>> <a href="#" class="tooltip" data-notable-ty="JoinHandle<F::Output>">ⓘ</a><div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> + 'static,
|
||||
F::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: 'static,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Spawns a <code>!Send</code> future on the current <a href="struct.LocalSet.html" title="struct tokio::task::LocalSet"><code>LocalSet</code></a> or <a href="struct@crate::runtime::LocalRuntime"><code>LocalRuntime</code></a>.</p>
|
||||
<p>The spawned future will run on the same thread that called <code>spawn_local</code>.</p>
|
||||
<p>The provided future will start running in the background immediately
|
||||
when <code>spawn_local</code> is called, even if you don’t await the returned
|
||||
<code>JoinHandle</code>.</p>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This function panics if called outside of a <a href="struct.LocalSet.html" title="struct tokio::task::LocalSet"><code>LocalSet</code></a>.</p>
|
||||
<p>Note that if <a href="fn.spawn.html" title="fn tokio::task::spawn"><code>tokio::spawn</code></a> is used from within a <code>LocalSet</code>, the
|
||||
resulting new task will <em>not</em> be inside the <code>LocalSet</code>, so you must use
|
||||
<code>spawn_local</code> if you want to stay within the <code>LocalSet</code>.</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>std::rc::Rc;
|
||||
<span class="kw">use </span>tokio::task;
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span>nonsend_data = Rc::new(<span class="string">"my nonsend data..."</span>);
|
||||
|
||||
<span class="kw">let </span>local = task::LocalSet::new();
|
||||
|
||||
<span class="comment">// Run the local task set.
|
||||
</span>local.run_until(<span class="kw">async move </span>{
|
||||
<span class="kw">let </span>nonsend_data = nonsend_data.clone();
|
||||
task::spawn_local(<span class="kw">async move </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"{}"</span>, nonsend_data);
|
||||
<span class="comment">// ...
|
||||
</span>}).<span class="kw">await</span>.unwrap();
|
||||
}).<span class="kw">await</span>;
|
||||
}</code></pre></div>
|
||||
</div></details><script type="text/json" id="notable-traits-data">{"JoinHandle<F::Output>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.JoinHandle.html\" title=\"struct tokio::task::JoinHandle\">JoinHandle</a><T></code></h3><pre><code><div class=\"where\">impl<T> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"struct.JoinHandle.html\" title=\"struct tokio::task::JoinHandle\">JoinHandle</a><T></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</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><T, <a class=\"struct\" href=\"struct.JoinError.html\" title=\"struct tokio::task::JoinError\">JoinError</a>>;</div>"}</script></section></div></main></body></html>
|
||||
6
tokio/task/fn.try_id.html
Normal file
6
tokio/task/fn.try_id.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="Returns the `Id` of the currently running task, or `None` if called outside of a task."><title>try_id in tokio::task - 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>task</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">task</a></span><h1>Function <span class="fn">try_id</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/runtime/task/id.rs.html#46-48">Source</a> </span></div><pre class="rust item-decl"><code>pub fn try_id() -> <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.Id.html" title="struct tokio::task::Id">Id</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Returns the <a href="struct.Id.html" title="struct tokio::task::Id"><code>Id</code></a> of the currently running task, or <code>None</code> if called outside
|
||||
of a task.</p>
|
||||
<p>This function is similar to <a href="fn.id.html" title="fn tokio::task::id"><code>task::id()</code></a>, except
|
||||
that it returns <code>None</code> rather than panicking if called outside of a task
|
||||
context.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
5
tokio/task/fn.unconstrained.html
Normal file
5
tokio/task/fn.unconstrained.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="Turn off cooperative scheduling for a future. The future will never be forced to yield by Tokio. Using this exposes your service to starvation if the unconstrained future never yields otherwise."><title>unconstrained in tokio::task - 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>task</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">task</a></span><h1>Function <span class="fn">unconstrained</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/task/unconstrained.rs.html#43-45">Source</a> </span></div><pre class="rust item-decl"><code>pub fn unconstrained<F>(inner: F) -> <a class="struct" href="struct.Unconstrained.html" title="struct tokio::task::Unconstrained">Unconstrained</a><F> <a href="#" class="tooltip" data-notable-ty="Unconstrained<F>">ⓘ</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Turn off cooperative scheduling for a future. The future will never be forced to yield by
|
||||
Tokio. Using this exposes your service to starvation if the unconstrained future never yields
|
||||
otherwise.</p>
|
||||
<p>See also the usage example in the <a href="index.html#unconstrained">task module</a>.</p>
|
||||
</div></details><script type="text/json" id="notable-traits-data">{"Unconstrained<F>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Unconstrained.html\" title=\"struct tokio::task::Unconstrained\">Unconstrained</a><F></code></h3><pre><code><div class=\"where\">impl<F> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"struct.Unconstrained.html\" title=\"struct tokio::task::Unconstrained\">Unconstrained</a><F><div class=\"where\">where\n F: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a>,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</a> = <F as <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a>>::<a class=\"associatedtype\" href=\"https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output\" title=\"type core::future::future::Future::Output\">Output</a>;</div>"}</script></section></div></main></body></html>
|
||||
24
tokio/task/fn.yield_now.html
Normal file
24
tokio/task/fn.yield_now.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="Yields execution back to the Tokio runtime."><title>yield_now in tokio::task - 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="#">yield_<wbr>now</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#non-guarantees" title="Non-guarantees">Non-guarantees</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>task</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">task</a></span><h1>Function <span class="fn">yield_now</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/task/yield_now.rs.html#39-64">Source</a> </span></div><pre class="rust item-decl"><code>pub async fn yield_now()</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Yields execution back to the Tokio runtime.</p>
|
||||
<p>A task yields by awaiting on <code>yield_now()</code>, and may resume when that future
|
||||
completes (with no output.) The current task will be re-added as a pending
|
||||
task at the <em>back</em> of the pending queue. Any other pending tasks will be
|
||||
scheduled. No other waking is required for the task to continue.</p>
|
||||
<p>See also the usage example in the <a href="index.html#yield_now">task module</a>.</p>
|
||||
<h3 id="non-guarantees"><a class="doc-anchor" href="#non-guarantees">§</a>Non-guarantees</h3>
|
||||
<p>This function may not yield all the way up to the executor if there are any
|
||||
special combinators above it in the call stack. For example, if a
|
||||
<a href="../macro.select.html" title="macro tokio::select"><code>tokio::select!</code></a> has another branch complete during the same poll as the
|
||||
<code>yield_now()</code>, then the yield is not propagated all the way up to the
|
||||
runtime.</p>
|
||||
<p>It is generally not guaranteed that the runtime behaves like you expect it
|
||||
to when deciding which task to schedule next after a call to <code>yield_now()</code>.
|
||||
In particular, the runtime may choose to poll the task that just ran
|
||||
<code>yield_now()</code> again immediately without polling any other tasks first. For
|
||||
example, the runtime will not drive the IO driver between every poll of a
|
||||
task, and this could result in the runtime polling the current task again
|
||||
immediately even if there is another task that could make progress if that
|
||||
other task is waiting for a notification from the IO driver.</p>
|
||||
<p>In general, changes to the order in which the runtime polls tasks is not
|
||||
considered a breaking change, and your program should be correct no matter
|
||||
which order the runtime polls your tasks in.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
3
tokio/task/futures/index.html
Normal file
3
tokio/task/futures/index.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="Task-related futures."><title>tokio::task::futures - 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 futures</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In tokio::<wbr>task</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">task</a></span><h1>Module <span>futures</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/task/mod.rs.html#370">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Task-related futures.</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.TaskLocalFuture.html" title="struct tokio::task::futures::TaskLocalFuture">Task<wbr>Local<wbr>Future</a></div><div class="desc docblock-short">A future that sets a value <code>T</code> of a task local for the future <code>F</code> during
|
||||
its execution.</div></li></ul></section></div></main></body></html>
|
||||
1
tokio/task/futures/sidebar-items.js
Normal file
1
tokio/task/futures/sidebar-items.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
window.SIDEBAR_ITEMS = {"struct":["TaskLocalFuture"]};
|
||||
68
tokio/task/futures/struct.TaskLocalFuture.html
Normal file
68
tokio/task/futures/struct.TaskLocalFuture.html
Normal file
File diff suppressed because one or more lines are too long
231
tokio/task/index.html
Normal file
231
tokio/task/index.html
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
<!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 green-threads."><title>tokio::task - 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 task</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#what-are-tasks" title="What are Tasks?">What are Tasks?</a></li><li><a href="#working-with-tasks" title="Working with Tasks">Working with Tasks</a><ul><li><a href="#spawning" title="Spawning">Spawning</a></li><li><a href="#blocking-and-yielding" title="Blocking and Yielding">Blocking and Yielding</a></li><li><a href="#cooperative-scheduling" title="Cooperative scheduling">Cooperative scheduling</a></li></ul></li></ul><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><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>task</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/task/mod.rs.html#1-373">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Asynchronous green-threads.</p>
|
||||
<h3 id="what-are-tasks"><a class="doc-anchor" href="#what-are-tasks">§</a>What are Tasks?</h3>
|
||||
<p>A <em>task</em> is a light weight, non-blocking unit of execution. A task is similar
|
||||
to an OS thread, but rather than being managed by the OS scheduler, they are
|
||||
managed by the <a href="../runtime/index.html" title="mod tokio::runtime">Tokio runtime</a>. Another name for this general pattern is
|
||||
<a href="https://en.wikipedia.org/wiki/Green_threads">green threads</a>. If you are familiar with <a href="https://tour.golang.org/concurrency/1">Go’s goroutines</a>, <a href="https://kotlinlang.org/docs/reference/coroutines-overview.html">Kotlin’s
|
||||
coroutines</a>, or <a href="http://erlang.org/doc/getting_started/conc_prog.html#processes">Erlang’s processes</a>, you can think of Tokio’s tasks as
|
||||
something similar.</p>
|
||||
<p>Key points about tasks include:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p>Tasks are <strong>light weight</strong>. Because tasks are scheduled by the Tokio
|
||||
runtime rather than the operating system, creating new tasks or switching
|
||||
between tasks does not require a context switch and has fairly low
|
||||
overhead. Creating, running, and destroying large numbers of tasks is
|
||||
quite cheap, especially compared to OS threads.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Tasks are scheduled <strong>cooperatively</strong>. Most operating systems implement
|
||||
<em>preemptive multitasking</em>. This is a scheduling technique where the
|
||||
operating system allows each thread to run for a period of time, and then
|
||||
<em>preempts</em> it, temporarily pausing that thread and switching to another.
|
||||
Tasks, on the other hand, implement <em>cooperative multitasking</em>. In
|
||||
cooperative multitasking, a task is allowed to run until it <em>yields</em>,
|
||||
indicating to the Tokio runtime’s scheduler that it cannot currently
|
||||
continue executing. When a task yields, the Tokio runtime switches to
|
||||
executing the next task.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Tasks are <strong>non-blocking</strong>. Typically, when an OS thread performs I/O or
|
||||
must synchronize with another thread, it <em>blocks</em>, allowing the OS to
|
||||
schedule another thread. When a task cannot continue executing, it must
|
||||
yield instead, allowing the Tokio runtime to schedule another task. Tasks
|
||||
should generally not perform system calls or other operations that could
|
||||
block a thread, as this would prevent other tasks running on the same
|
||||
thread from executing as well. Instead, this module provides APIs for
|
||||
running blocking operations in an asynchronous context.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<h3 id="working-with-tasks"><a class="doc-anchor" href="#working-with-tasks">§</a>Working with Tasks</h3>
|
||||
<p>This module provides the following APIs for working with tasks:</p>
|
||||
<h4 id="spawning"><a class="doc-anchor" href="#spawning">§</a>Spawning</h4>
|
||||
<p>Perhaps the most important function in this module is <a href="fn.spawn.html" title="fn tokio::task::spawn"><code>task::spawn</code></a>. This
|
||||
function can be thought of as an async equivalent to the standard library’s
|
||||
<a href="https://doc.rust-lang.org/1.84.1/std/thread/fn.spawn.html" title="fn std::thread::spawn"><code>thread::spawn</code></a>. It takes an <code>async</code> block or other
|
||||
<a href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">future</a>, and creates a new task to run that work concurrently:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
|
||||
task::spawn(<span class="kw">async </span>{
|
||||
<span class="comment">// perform some work here...
|
||||
</span>});</code></pre></div>
|
||||
<p>Like <a href="https://doc.rust-lang.org/1.84.1/std/thread/fn.spawn.html" title="fn std::thread::spawn"><code>std::thread::spawn</code></a>, <code>task::spawn</code> returns a <a href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle"><code>JoinHandle</code></a> struct.
|
||||
A <code>JoinHandle</code> is itself a future which may be used to await the output of
|
||||
the spawned task. For example:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
|
||||
<span class="kw">let </span>join = task::spawn(<span class="kw">async </span>{
|
||||
<span class="comment">// ...
|
||||
</span><span class="string">"hello world!"
|
||||
</span>});
|
||||
|
||||
<span class="comment">// ...
|
||||
|
||||
// Await the result of the spawned task.
|
||||
</span><span class="kw">let </span>result = join.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">assert_eq!</span>(result, <span class="string">"hello world!"</span>);</code></pre></div>
|
||||
<p>Again, like <code>std::thread</code>’s <a href="https://doc.rust-lang.org/1.84.1/std/thread/struct.JoinHandle.html" title="struct std::thread::JoinHandle"><code>JoinHandle</code> type</a>, if the spawned
|
||||
task panics, awaiting its <code>JoinHandle</code> will return a <a href="struct.JoinError.html" title="struct tokio::task::JoinError"><code>JoinError</code></a>. For
|
||||
example:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
|
||||
<span class="kw">let </span>join = task::spawn(<span class="kw">async </span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"something bad happened!"</span>)
|
||||
});
|
||||
|
||||
<span class="comment">// The returned result indicates that the task failed.
|
||||
</span><span class="macro">assert!</span>(join.<span class="kw">await</span>.is_err());</code></pre></div>
|
||||
<p><code>spawn</code>, <code>JoinHandle</code>, and <code>JoinError</code> are present when the “rt”
|
||||
feature flag is enabled.</p>
|
||||
<h5 id="cancellation"><a class="doc-anchor" href="#cancellation">§</a>Cancellation</h5>
|
||||
<p>Spawned tasks may be cancelled using the <a href="struct.JoinHandle.html#method.abort" title="method tokio::task::JoinHandle::abort"><code>JoinHandle::abort</code></a> or
|
||||
<a href="struct.AbortHandle.html#method.abort" title="method tokio::task::AbortHandle::abort"><code>AbortHandle::abort</code></a> methods. When one of these methods are called, the
|
||||
task is signalled to shut down next time it yields at an <code>.await</code> point. If
|
||||
the task is already idle, then it will be shut down as soon as possible
|
||||
without running again before being shut down. Additionally, shutting down a
|
||||
Tokio runtime (e.g. by returning from <code>#[tokio::main]</code>) immediately cancels
|
||||
all tasks on it.</p>
|
||||
<p>When tasks are shut down, it will stop running at whichever <code>.await</code> it has
|
||||
yielded at. All local variables are destroyed by running their destructor.
|
||||
Once shutdown has completed, awaiting the <a href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle"><code>JoinHandle</code></a> will fail with a
|
||||
<a href="struct.JoinError.html#method.is_cancelled" title="method tokio::task::JoinError::is_cancelled">cancelled error</a>.</p>
|
||||
<p>Note that aborting a task does not guarantee that it fails with a cancelled
|
||||
error, since it may complete normally first. For example, if the task does
|
||||
not yield to the runtime at any point between the call to <code>abort</code> and the
|
||||
end of the task, then the <a href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle"><code>JoinHandle</code></a> will instead report that the task
|
||||
exited normally.</p>
|
||||
<p>Be aware that tasks spawned using <a href="fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>spawn_blocking</code></a> cannot be aborted
|
||||
because they are not async. If you call <code>abort</code> on a <code>spawn_blocking</code>
|
||||
task, then this <em>will not have any effect</em>, and the task will continue
|
||||
running normally. The exception is if the task has not started running
|
||||
yet; in that case, calling <code>abort</code> may prevent the task from starting.</p>
|
||||
<p>Be aware that calls to <a href="struct.JoinHandle.html#method.abort" title="method tokio::task::JoinHandle::abort"><code>JoinHandle::abort</code></a> just schedule the task for
|
||||
cancellation, and will return before the cancellation has completed. To wait
|
||||
for cancellation to complete, wait for the task to finish by awaiting the
|
||||
<a href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle"><code>JoinHandle</code></a>. Similarly, the <a href="struct.JoinHandle.html#method.is_finished" title="method tokio::task::JoinHandle::is_finished"><code>JoinHandle::is_finished</code></a> method does not
|
||||
return <code>true</code> until the cancellation has finished.</p>
|
||||
<p>Calling <a href="struct.JoinHandle.html#method.abort" title="method tokio::task::JoinHandle::abort"><code>JoinHandle::abort</code></a> multiple times has the same effect as calling
|
||||
it once.</p>
|
||||
<p>Tokio also provides an <a href="struct.AbortHandle.html" title="struct tokio::task::AbortHandle"><code>AbortHandle</code></a>, which is like the <a href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle"><code>JoinHandle</code></a>,
|
||||
except that it does not provide a mechanism to wait for the task to finish.
|
||||
Each task can only have one <a href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle"><code>JoinHandle</code></a>, but it can have more than one
|
||||
<a href="struct.AbortHandle.html" title="struct tokio::task::AbortHandle"><code>AbortHandle</code></a>.</p>
|
||||
<h4 id="blocking-and-yielding"><a class="doc-anchor" href="#blocking-and-yielding">§</a>Blocking and Yielding</h4>
|
||||
<p>As we discussed above, code running in asynchronous tasks should not perform
|
||||
operations that can block. A blocking operation performed in a task running
|
||||
on a thread that is also running other tasks would block the entire thread,
|
||||
preventing other tasks from running.</p>
|
||||
<p>Instead, Tokio provides two APIs for running blocking operations in an
|
||||
asynchronous context: <a href="fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking"><code>task::spawn_blocking</code></a> and <a href="fn.block_in_place.html" title="fn tokio::task::block_in_place"><code>task::block_in_place</code></a>.</p>
|
||||
<p>Be aware that if you call a non-async method from async code, that non-async
|
||||
method is still inside the asynchronous context, so you should also avoid
|
||||
blocking operations there. This includes destructors of objects destroyed in
|
||||
async code.</p>
|
||||
<h5 id="spawn_blocking"><a class="doc-anchor" href="#spawn_blocking">§</a><code>spawn_blocking</code></h5>
|
||||
<p>The <code>task::spawn_blocking</code> function is similar to the <code>task::spawn</code> function
|
||||
discussed in the previous section, but rather than spawning an
|
||||
<em>non-blocking</em> future on the Tokio runtime, it instead spawns a
|
||||
<em>blocking</em> function on a dedicated thread pool for blocking tasks. For
|
||||
example:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
|
||||
task::spawn_blocking(|| {
|
||||
<span class="comment">// do some compute-heavy work or call synchronous code
|
||||
</span>});</code></pre></div>
|
||||
<p>Just like <code>task::spawn</code>, <code>task::spawn_blocking</code> returns a <code>JoinHandle</code>
|
||||
which we can use to await the result of the blocking operation:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>join = task::spawn_blocking(|| {
|
||||
<span class="comment">// do some compute-heavy work or call synchronous code
|
||||
</span><span class="string">"blocking completed"
|
||||
</span>});
|
||||
|
||||
<span class="kw">let </span>result = join.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">assert_eq!</span>(result, <span class="string">"blocking completed"</span>);</code></pre></div>
|
||||
<h5 id="block_in_place"><a class="doc-anchor" href="#block_in_place">§</a><code>block_in_place</code></h5>
|
||||
<p>When using the <a href="../runtime/index.html#threaded-scheduler">multi-threaded runtime</a>, the <a href="fn.block_in_place.html" title="fn tokio::task::block_in_place"><code>task::block_in_place</code></a>
|
||||
function is also available. Like <code>task::spawn_blocking</code>, this function
|
||||
allows running a blocking operation from an asynchronous context. Unlike
|
||||
<code>spawn_blocking</code>, however, <code>block_in_place</code> works by transitioning the
|
||||
<em>current</em> worker thread to a blocking thread, moving other tasks running on
|
||||
that thread to another worker thread. This can improve performance by avoiding
|
||||
context switches.</p>
|
||||
<p>For example:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
|
||||
<span class="kw">let </span>result = task::block_in_place(|| {
|
||||
<span class="comment">// do some compute-heavy work or call synchronous code
|
||||
</span><span class="string">"blocking completed"
|
||||
</span>});
|
||||
|
||||
<span class="macro">assert_eq!</span>(result, <span class="string">"blocking completed"</span>);</code></pre></div>
|
||||
<h5 id="yield_now"><a class="doc-anchor" href="#yield_now">§</a><code>yield_now</code></h5>
|
||||
<p>In addition, this module provides a <a href="fn.yield_now.html" title="fn tokio::task::yield_now"><code>task::yield_now</code></a> async function
|
||||
that is analogous to the standard library’s <a href="https://doc.rust-lang.org/1.84.1/std/thread/fn.yield_now.html" title="fn std::thread::yield_now"><code>thread::yield_now</code></a>. Calling
|
||||
and <code>await</code>ing this function will cause the current task to yield to the
|
||||
Tokio runtime’s scheduler, allowing other tasks to be
|
||||
scheduled. Eventually, the yielding task will be polled again, allowing it
|
||||
to execute. For example:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
|
||||
<span class="kw">async </span>{
|
||||
task::spawn(<span class="kw">async </span>{
|
||||
<span class="comment">// ...
|
||||
</span><span class="macro">println!</span>(<span class="string">"spawned task done!"</span>)
|
||||
});
|
||||
|
||||
<span class="comment">// Yield, allowing the newly-spawned task to execute first.
|
||||
</span>task::yield_now().<span class="kw">await</span>;
|
||||
<span class="macro">println!</span>(<span class="string">"main task done!"</span>);
|
||||
}</code></pre></div>
|
||||
<h4 id="cooperative-scheduling"><a class="doc-anchor" href="#cooperative-scheduling">§</a>Cooperative scheduling</h4>
|
||||
<p>A single call to <a href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#tymethod.poll" title="method core::future::future::Future::poll"><code>poll</code></a> on a top-level task may potentially do a lot of
|
||||
work before it returns <code>Poll::Pending</code>. If a task runs for a long period of
|
||||
time without yielding back to the executor, it can starve other tasks
|
||||
waiting on that executor to execute them, or drive underlying resources.
|
||||
Since Rust does not have a runtime, it is difficult to forcibly preempt a
|
||||
long-running task. Instead, this module provides an opt-in mechanism for
|
||||
futures to collaborate with the executor to avoid starvation.</p>
|
||||
<p>Consider a future like this one:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>drop_all<I: Stream + Unpin>(<span class="kw-2">mut </span>input: I) {
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(<span class="kw">_</span>) = input.next().<span class="kw">await </span>{}
|
||||
}</code></pre></div>
|
||||
<p>It may look harmless, but consider what happens under heavy load if the
|
||||
input stream is <em>always</em> ready. If we spawn <code>drop_all</code>, the task will never
|
||||
yield, and will starve other tasks and resources on the same executor.</p>
|
||||
<p>To account for this, Tokio has explicit yield points in a number of library
|
||||
functions, which force tasks to return to the executor periodically.</p>
|
||||
<h5 id="unconstrained"><a class="doc-anchor" href="#unconstrained">§</a>unconstrained</h5>
|
||||
<p>If necessary, <a href="fn.unconstrained.html" title="fn tokio::task::unconstrained"><code>task::unconstrained</code></a> lets you opt a future out of Tokio’s cooperative
|
||||
scheduling. When a future is wrapped with <code>unconstrained</code>, it will never be forced to yield to
|
||||
Tokio. For example:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::{task, sync::mpsc};
|
||||
|
||||
<span class="kw">let </span>fut = <span class="kw">async </span>{
|
||||
<span class="kw">let </span>(tx, <span class="kw-2">mut </span>rx) = mpsc::unbounded_channel();
|
||||
|
||||
<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..<span class="number">1000 </span>{
|
||||
<span class="kw">let _ </span>= tx.send(());
|
||||
<span class="comment">// This will always be ready. If coop was in effect, this code would be forced to yield
|
||||
// periodically. However, if left unconstrained, then this code will never yield.
|
||||
</span>rx.recv().<span class="kw">await</span>;
|
||||
}
|
||||
};
|
||||
|
||||
task::unconstrained(fut).<span class="kw">await</span>;</code></pre></div>
|
||||
</div></details><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="futures/index.html" title="mod tokio::task::futures">futures</a></div><div class="desc docblock-short">Task-related futures.</div></li></ul><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.AbortHandle.html" title="struct tokio::task::AbortHandle">Abort<wbr>Handle</a></div><div class="desc docblock-short">An owned permission to abort a spawned task, without awaiting its completion.</div></li><li><div class="item-name"><a class="struct" href="struct.Id.html" title="struct tokio::task::Id">Id</a></div><div class="desc docblock-short">An opaque ID that uniquely identifies a task relative to all other currently
|
||||
running tasks.</div></li><li><div class="item-name"><a class="struct" href="struct.JoinError.html" title="struct tokio::task::JoinError">Join<wbr>Error</a></div><div class="desc docblock-short">Task failed to execute to completion.</div></li><li><div class="item-name"><a class="struct" href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle">Join<wbr>Handle</a></div><div class="desc docblock-short">An owned permission to join on a task (await its termination).</div></li><li><div class="item-name"><a class="struct" href="struct.JoinSet.html" title="struct tokio::task::JoinSet">JoinSet</a></div><div class="desc docblock-short">A collection of tasks spawned on a Tokio runtime.</div></li><li><div class="item-name"><a class="struct" href="struct.LocalEnterGuard.html" title="struct tokio::task::LocalEnterGuard">Local<wbr>Enter<wbr>Guard</a></div><div class="desc docblock-short">Context guard for <code>LocalSet</code></div></li><li><div class="item-name"><a class="struct" href="struct.LocalKey.html" title="struct tokio::task::LocalKey">Local<wbr>Key</a></div><div class="desc docblock-short">A key for task-local data.</div></li><li><div class="item-name"><a class="struct" href="struct.LocalSet.html" title="struct tokio::task::LocalSet">Local<wbr>Set</a></div><div class="desc docblock-short">A set of tasks which are executed on the same thread.</div></li><li><div class="item-name"><a class="struct" href="struct.Unconstrained.html" title="struct tokio::task::Unconstrained">Unconstrained</a></div><div class="desc docblock-short">Future for the <a href="fn.unconstrained.html" title="fn tokio::task::unconstrained"><code>unconstrained</code></a> method.</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.block_in_place.html" title="fn tokio::task::block_in_place">block_<wbr>in_<wbr>place</a></div><div class="desc docblock-short">Runs the provided blocking function on the current thread without
|
||||
blocking the executor.</div></li><li><div class="item-name"><a class="fn" href="fn.consume_budget.html" title="fn tokio::task::consume_budget">consume_<wbr>budget</a></div><div class="desc docblock-short">Consumes a unit of budget and returns the execution back to the Tokio
|
||||
runtime <em>if</em> the task’s coop budget was exhausted.</div></li><li><div class="item-name"><a class="fn" href="fn.id.html" title="fn tokio::task::id">id</a></div><div class="desc docblock-short">Returns the <a href="struct.Id.html" title="struct tokio::task::Id"><code>Id</code></a> of the currently running task.</div></li><li><div class="item-name"><a class="fn" href="fn.spawn.html" title="fn tokio::task::spawn">spawn</a></div><div class="desc docblock-short">Spawns a new asynchronous task, returning a
|
||||
<a href="struct.JoinHandle.html" title="struct tokio::task::JoinHandle"><code>JoinHandle</code></a> for it.</div></li><li><div class="item-name"><a class="fn" href="fn.spawn_blocking.html" title="fn tokio::task::spawn_blocking">spawn_<wbr>blocking</a></div><div class="desc docblock-short">Runs the provided closure on a thread where blocking is acceptable.</div></li><li><div class="item-name"><a class="fn" href="fn.spawn_local.html" title="fn tokio::task::spawn_local">spawn_<wbr>local</a></div><div class="desc docblock-short">Spawns a <code>!Send</code> future on the current <a href="struct.LocalSet.html" title="struct tokio::task::LocalSet"><code>LocalSet</code></a> or <a href="struct@crate::runtime::LocalRuntime"><code>LocalRuntime</code></a>.</div></li><li><div class="item-name"><a class="fn" href="fn.try_id.html" title="fn tokio::task::try_id">try_id</a></div><div class="desc docblock-short">Returns the <a href="struct.Id.html" title="struct tokio::task::Id"><code>Id</code></a> of the currently running task, or <code>None</code> if called outside
|
||||
of a task.</div></li><li><div class="item-name"><a class="fn" href="fn.unconstrained.html" title="fn tokio::task::unconstrained">unconstrained</a></div><div class="desc docblock-short">Turn off cooperative scheduling for a future. The future will never be forced to yield by
|
||||
Tokio. Using this exposes your service to starvation if the unconstrained future never yields
|
||||
otherwise.</div></li><li><div class="item-name"><a class="fn" href="fn.yield_now.html" title="fn tokio::task::yield_now">yield_<wbr>now</a></div><div class="desc docblock-short">Yields execution back to the Tokio runtime.</div></li></ul></section></div></main></body></html>
|
||||
11
tokio/task/join_set/struct.JoinSet.html
Normal file
11
tokio/task/join_set/struct.JoinSet.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/struct.JoinSet.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/struct.JoinSet.html">../../../tokio/task/struct.JoinSet.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/struct.JoinSet.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/task/local/fn.spawn_local.html
Normal file
11
tokio/task/local/fn.spawn_local.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/fn.spawn_local.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/fn.spawn_local.html">../../../tokio/task/fn.spawn_local.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/fn.spawn_local.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/task/local/struct.LocalEnterGuard.html
Normal file
11
tokio/task/local/struct.LocalEnterGuard.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/struct.LocalEnterGuard.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/struct.LocalEnterGuard.html">../../../tokio/task/struct.LocalEnterGuard.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/struct.LocalEnterGuard.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/task/local/struct.LocalSet.html
Normal file
11
tokio/task/local/struct.LocalSet.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/struct.LocalSet.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/struct.LocalSet.html">../../../tokio/task/struct.LocalSet.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/struct.LocalSet.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
1
tokio/task/sidebar-items.js
Normal file
1
tokio/task/sidebar-items.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
window.SIDEBAR_ITEMS = {"fn":["block_in_place","consume_budget","id","spawn","spawn_blocking","spawn_local","try_id","unconstrained","yield_now"],"mod":["futures"],"struct":["AbortHandle","Id","JoinError","JoinHandle","JoinSet","LocalEnterGuard","LocalKey","LocalSet","Unconstrained"]};
|
||||
11
tokio/task/spawn/fn.spawn.html
Normal file
11
tokio/task/spawn/fn.spawn.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/fn.spawn.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/fn.spawn.html">../../../tokio/task/fn.spawn.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/fn.spawn.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
44
tokio/task/struct.AbortHandle.html
Normal file
44
tokio/task/struct.AbortHandle.html
Normal file
File diff suppressed because one or more lines are too long
30
tokio/task/struct.Id.html
Normal file
30
tokio/task/struct.Id.html
Normal file
File diff suppressed because one or more lines are too long
65
tokio/task/struct.JoinError.html
Normal file
65
tokio/task/struct.JoinError.html
Normal file
File diff suppressed because one or more lines are too long
199
tokio/task/struct.JoinHandle.html
Normal file
199
tokio/task/struct.JoinHandle.html
Normal file
File diff suppressed because one or more lines are too long
268
tokio/task/struct.JoinSet.html
Normal file
268
tokio/task/struct.JoinSet.html
Normal file
File diff suppressed because one or more lines are too long
12
tokio/task/struct.LocalEnterGuard.html
Normal file
12
tokio/task/struct.LocalEnterGuard.html
Normal file
File diff suppressed because one or more lines are too long
74
tokio/task/struct.LocalKey.html
Normal file
74
tokio/task/struct.LocalKey.html
Normal file
File diff suppressed because one or more lines are too long
298
tokio/task/struct.LocalSet.html
Normal file
298
tokio/task/struct.LocalSet.html
Normal file
File diff suppressed because one or more lines are too long
21
tokio/task/struct.Unconstrained.html
Normal file
21
tokio/task/struct.Unconstrained.html
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<!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="Future for the `unconstrained` method."><title>Unconstrained in tokio::task - 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="#">Unconstrained</a></h2><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Future-for-Unconstrained%3CF%3E" title="Future">Future</a></li><li><a href="#impl-Unpin-for-Unconstrained%3CF%3E" title="Unpin">Unpin</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Freeze-for-Unconstrained%3CF%3E" title="Freeze">Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-Unconstrained%3CF%3E" title="RefUnwindSafe">RefUnwindSafe</a></li><li><a href="#impl-Send-for-Unconstrained%3CF%3E" title="Send">Send</a></li><li><a href="#impl-Sync-for-Unconstrained%3CF%3E" title="Sync">Sync</a></li><li><a href="#impl-UnwindSafe-for-Unconstrained%3CF%3E" 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-IntoFuture-for-F" title="IntoFuture">IntoFuture</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>task</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">task</a></span><h1>Struct <span class="struct">Unconstrained</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/task/unconstrained.rs.html#6-14">Source</a> </span></div><pre class="rust item-decl"><code>pub struct Unconstrained<F> { <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>Future for the <a href="fn.unconstrained.html" title="fn tokio::task::unconstrained"><code>unconstrained</code></a> method.</p>
|
||||
</div></details><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-Future-for-Unconstrained%3CF%3E" class="impl"><a class="src rightside" href="../../src/tokio/task/unconstrained.rs.html#16-35">Source</a><a href="#impl-Future-for-Unconstrained%3CF%3E" class="anchor">§</a><h3 class="code-header">impl<F> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="struct.Unconstrained.html" title="struct tokio::task::Unconstrained">Unconstrained</a><F><div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Output" class="associatedtype trait-impl"><a class="src rightside" href="../../src/tokio/task/unconstrained.rs.html#20">Source</a><a href="#associatedtype.Output" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <F as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a></h4></section></summary><div class='docblock'>The type of value produced on completion.</div></details><details class="toggle method-toggle" open><summary><section id="method.poll" class="method trait-impl"><a class="src rightside" href="../../src/tokio/task/unconstrained.rs.html#23-26">Source</a><a href="#method.poll" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#tymethod.poll" class="fn">poll</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</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><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>></h4></section></summary><div class='docblock'>Attempts to resolve the future to a final value, registering
|
||||
the current task for wakeup if the value is not yet available. <a href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#tymethod.poll">Read more</a></div></details></div></details><section id="impl-Unpin-for-Unconstrained%3CF%3E" class="impl"><a class="src rightside" href="../../src/tokio/task/unconstrained.rs.html#6-14">Source</a><a href="#impl-Unpin-for-Unconstrained%3CF%3E" class="anchor">§</a><h3 class="code-header">impl<'__pin, F> <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.Unconstrained.html" title="struct tokio::task::Unconstrained">Unconstrained</a><F><div class="where">where
|
||||
PinnedFieldsOf<__Origin<'__pin, F>>: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></h3></section></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-Unconstrained%3CF%3E" class="impl"><a href="#impl-Freeze-for-Unconstrained%3CF%3E" class="anchor">§</a><h3 class="code-header">impl<F> <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.Unconstrained.html" title="struct tokio::task::Unconstrained">Unconstrained</a><F><div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a>,</div></h3></section><section id="impl-RefUnwindSafe-for-Unconstrained%3CF%3E" class="impl"><a href="#impl-RefUnwindSafe-for-Unconstrained%3CF%3E" class="anchor">§</a><h3 class="code-header">impl<F> <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.Unconstrained.html" title="struct tokio::task::Unconstrained">Unconstrained</a><F><div class="where">where
|
||||
F: <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>,</div></h3></section><section id="impl-Send-for-Unconstrained%3CF%3E" class="impl"><a href="#impl-Send-for-Unconstrained%3CF%3E" class="anchor">§</a><h3 class="code-header">impl<F> <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.Unconstrained.html" title="struct tokio::task::Unconstrained">Unconstrained</a><F><div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,</div></h3></section><section id="impl-Sync-for-Unconstrained%3CF%3E" class="impl"><a href="#impl-Sync-for-Unconstrained%3CF%3E" class="anchor">§</a><h3 class="code-header">impl<F> <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.Unconstrained.html" title="struct tokio::task::Unconstrained">Unconstrained</a><F><div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>,</div></h3></section><section id="impl-UnwindSafe-for-Unconstrained%3CF%3E" class="impl"><a href="#impl-UnwindSafe-for-Unconstrained%3CF%3E" class="anchor">§</a><h3 class="code-header">impl<F> <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.Unconstrained.html" title="struct tokio::task::Unconstrained">Unconstrained</a><F><div class="where">where
|
||||
F: <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>,</div></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-IntoFuture-for-F" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/future/into_future.rs.html#138">Source</a><a href="#impl-IntoFuture-for-F" class="anchor">§</a><h3 class="code-header">impl<F> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/future/into_future/trait.IntoFuture.html" title="trait core::future::into_future::IntoFuture">IntoFuture</a> for F<div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Output-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/future/into_future.rs.html#139">Source</a><a href="#associatedtype.Output-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/core/future/into_future/trait.IntoFuture.html#associatedtype.Output" class="associatedtype">Output</a> = <F as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a></h4></section></summary><div class='docblock'>The output that the future will produce on completion.</div></details><details class="toggle" open><summary><section id="associatedtype.IntoFuture" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/future/into_future.rs.html#140">Source</a><a href="#associatedtype.IntoFuture" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/core/future/into_future/trait.IntoFuture.html#associatedtype.IntoFuture" class="associatedtype">IntoFuture</a> = F</h4></section></summary><div class='docblock'>Which kind of future are we turning this into?</div></details><details class="toggle method-toggle" open><summary><section id="method.into_future" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/future/into_future.rs.html#142">Source</a><a href="#method.into_future" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/future/into_future/trait.IntoFuture.html#tymethod.into_future" class="fn">into_future</a>(self) -> <F as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/future/into_future/trait.IntoFuture.html" title="trait core::future::into_future::IntoFuture">IntoFuture</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/future/into_future/trait.IntoFuture.html#associatedtype.IntoFuture" title="type core::future::into_future::IntoFuture::IntoFuture">IntoFuture</a></h4></section></summary><div class='docblock'>Creates a future from a value. <a href="https://doc.rust-lang.org/1.84.1/core/future/into_future/trait.IntoFuture.html#tymethod.into_future">Read more</a></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/task/task_local/struct.LocalKey.html
Normal file
11
tokio/task/task_local/struct.LocalKey.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/struct.LocalKey.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/struct.LocalKey.html">../../../tokio/task/struct.LocalKey.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/struct.LocalKey.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/task/task_local/struct.TaskLocalFuture.html
Normal file
11
tokio/task/task_local/struct.TaskLocalFuture.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/futures/struct.TaskLocalFuture.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/futures/struct.TaskLocalFuture.html">../../../tokio/task/futures/struct.TaskLocalFuture.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/futures/struct.TaskLocalFuture.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/task/unconstrained/fn.unconstrained.html
Normal file
11
tokio/task/unconstrained/fn.unconstrained.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/fn.unconstrained.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/fn.unconstrained.html">../../../tokio/task/fn.unconstrained.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/fn.unconstrained.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/task/unconstrained/struct.Unconstrained.html
Normal file
11
tokio/task/unconstrained/struct.Unconstrained.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/struct.Unconstrained.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/struct.Unconstrained.html">../../../tokio/task/struct.Unconstrained.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/struct.Unconstrained.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
tokio/task/yield_now/fn.yield_now.html
Normal file
11
tokio/task/yield_now/fn.yield_now.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../tokio/task/fn.yield_now.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../tokio/task/fn.yield_now.html">../../../tokio/task/fn.yield_now.html</a>...</p>
|
||||
<script>location.replace("../../../tokio/task/fn.yield_now.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue