This repository has been archived on 2022-04-04. You can view files and clone it, but cannot push or open issues or pull requests.

251 lines
27 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A runtime for writing reliable network applications without compromising speed."><meta name="keywords" content="rust, rustlang, rust-lang, tokio"><title>tokio - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../dark.css" disabled><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script src="../crates.js"></script><script defer src="../main.js"></script>
<noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">&#9776;</div><a class="sidebar-logo" href="../tokio/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.png" alt="logo"></div>
</a><h2 class="location">Crate tokio</h2><div class="block version"><div class="narrow-helper"></div><p>Version 1.17.0</p></div><div class="sidebar-elems"><a id="all-types" href="all.html"><p>See all tokio's items</p></a><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li><li><a href="#functions">Functions</a></li></ul></div><div id="sidebar-vars" data-name="tokio" data-ty="mod" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../tokio/index.html"><img class="rust-logo" src="../rust-logo.png" alt="logo"></a><nav class="sub"><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="18" height="18" alt="Pick another theme!" src="../brush.svg"></button><div id="theme-choices" role="menu"></div></div><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../settings.html" title="settings"><img width="18" height="18" alt="Change settings" src="../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><h1 class="fqn"><span class="in-band">Crate <a class="mod" href="#">tokio</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/tokio/lib.rs.html#1-537" title="goto source code">[src]</a></span></h1><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A runtime for writing reliable network applications without compromising speed.</p>
<p>Tokio is an event-driven, non-blocking I/O platform for writing asynchronous
applications with the Rust programming language. At a high level, it
provides a few major components:</p>
<ul>
<li>Tools for <a href="#working-with-tasks">working with asynchronous tasks</a>, including
<a href="crate::sync">synchronization primitives and channels</a> and <a href="crate::time">timeouts, sleeps, and
intervals</a>.</li>
<li>APIs for <a href="#asynchronous-io">performing asynchronous I/O</a>, including <a href="net/index.html">TCP and UDP</a> sockets,
<a href="crate::fs">filesystem</a> operations, and <a href="crate::process">process</a> and <a href="crate::signal">signal</a> management.</li>
<li>A <a href="runtime/index.html">runtime</a> for executing asynchronous code, including a task scheduler,
an I/O driver backed by the operating systems event queue (epoll, kqueue,
IOCP, etc…), and a high performance timer.</li>
</ul>
<p>Guide level documentation is found on the <a href="https://tokio.rs/tokio/tutorial">website</a>.</p>
<h2 id="a-tour-of-tokio" class="section-header"><a href="#a-tour-of-tokio">A Tour of Tokio</a></h2>
<p>Tokio consists of a number of modules that provide a range of functionality
essential for implementing asynchronous applications in Rust. In this
section, we will take a brief tour of Tokio, summarizing the major APIs and
their uses.</p>
<p>The easiest way to get started is to enable all features. Do this by
enabling the <code>full</code> feature flag:</p>
<div class="example-wrap"><pre class="language-toml"><code>tokio = { version = &quot;1&quot;, features = [&quot;full&quot;] }</code></pre></div><h4 id="authoring-applications" class="section-header"><a href="#authoring-applications">Authoring applications</a></h4>
<p>Tokio is great for writing applications and most users in this case shouldnt
worry too much about what features they should pick. If youre unsure, we suggest
going with <code>full</code> to ensure that you dont run into any road blocks while youre
building your application.</p>
<h5 id="example" class="section-header"><a href="#example">Example</a></h5>
<p>This example shows the quickest way to get started with Tokio.</p>
<div class="example-wrap"><pre class="language-toml"><code>tokio = { version = &quot;1&quot;, features = [&quot;full&quot;] }</code></pre></div><h4 id="authoring-libraries" class="section-header"><a href="#authoring-libraries">Authoring libraries</a></h4>
<p>As a library author your goal should be to provide the lightest weight crate
that is based on Tokio. To achieve this you should ensure that you only enable
the features you need. This allows users to pick up your crate without having
to enable unnecessary features.</p>
<h5 id="example-1" class="section-header"><a href="#example-1">Example</a></h5>
<p>This example shows how you may want to import features for a library that just
needs to <code>tokio::spawn</code> and use a <code>TcpStream</code>.</p>
<div class="example-wrap"><pre class="language-toml"><code>tokio = { version = &quot;1&quot;, features = [&quot;rt&quot;, &quot;net&quot;] }</code></pre></div><h3 id="working-with-tasks" class="section-header"><a href="#working-with-tasks">Working With Tasks</a></h3>
<p>Asynchronous programs in Rust are based around lightweight, non-blocking
units of execution called <a href="#working-with-tasks"><em>tasks</em></a>. The <a href="task/index.html"><code>tokio::task</code></a> module provides
important tools for working with tasks:</p>
<ul>
<li>The <a href="task/fn.spawn.html"><code>spawn</code></a> function and <a href="task/struct.JoinHandle.html"><code>JoinHandle</code></a> type, for scheduling a new task
on the Tokio runtime and awaiting the output of a spawned task, respectively,</li>
<li>Functions for <a href="task/index.html#blocking-and-yielding">running blocking operations</a> in an asynchronous
task context.</li>
</ul>
<p>The <a href="task/index.html"><code>tokio::task</code></a> module is present only when the “rt” feature flag
is enabled.</p>
<p>The <a href="crate::sync"><code>tokio::sync</code></a> module contains synchronization primitives to use when
needing to communicate or share data. These include:</p>
<ul>
<li>channels (<a href="crate::sync::oneshot"><code>oneshot</code></a>, <a href="crate::sync::mpsc"><code>mpsc</code></a>, and <a href="crate::sync::watch"><code>watch</code></a>), for sending values
between tasks,</li>
<li>a non-blocking <a href="crate::sync::Mutex"><code>Mutex</code></a>, for controlling access to a shared, mutable
value,</li>
<li>an asynchronous <a href="crate::sync::Barrier"><code>Barrier</code></a> type, for multiple tasks to synchronize before
beginning a computation.</li>
</ul>
<p>The <code>tokio::sync</code> module is present only when the “sync” feature flag is
enabled.</p>
<p>The <a href="crate::time"><code>tokio::time</code></a> module provides utilities for tracking time and
scheduling work. This includes functions for setting <a href="crate::time::timeout()">timeouts</a> for
tasks, <a href="crate::time::sleep()">sleeping</a> work to run in the future, or <a href="crate::time::interval()">repeating an operation at an
interval</a>.</p>
<p>In order to use <code>tokio::time</code>, the “time” feature flag must be enabled.</p>
<p>Finally, Tokio provides a <em>runtime</em> for executing asynchronous tasks. Most
applications can use the <a href="attr.main.html"><code>#[tokio::main]</code></a> macro to run their code on the
Tokio runtime. However, this macro provides only basic configuration options. As
an alternative, the <a href="runtime/index.html"><code>tokio::runtime</code></a> module provides more powerful APIs for configuring
and managing runtimes. You should use that module if the <code>#[tokio::main]</code> macro doesnt
provide the functionality you need.</p>
<p>Using the runtime requires the “rt” or “rt-multi-thread” feature flags, to
enable the basic <a href="runtime/index.html#current-thread-scheduler">single-threaded scheduler</a> and the <a href="runtime/index.html#multi-thread-scheduler">thread-pool
scheduler</a>, respectively. See the <a href="runtime/index.html#runtime-scheduler"><code>runtime</code> module
documentation</a> for details. In addition, the “macros” feature
flag enables the <code>#[tokio::main]</code> and <code>#[tokio::test]</code> attributes.</p>
<h3 id="cpu-bound-tasks-and-blocking-code" class="section-header"><a href="#cpu-bound-tasks-and-blocking-code">CPU-bound tasks and blocking code</a></h3>
<p>Tokio is able to concurrently run many tasks on a few threads by repeatedly
swapping the currently running task on each thread. However, this kind of
swapping can only happen at <code>.await</code> points, so code that spends a long time
without reaching an <code>.await</code> will prevent other tasks from running. To
combat this, Tokio provides two kinds of threads: Core threads and blocking
threads. The core threads are where all asynchronous code runs, and Tokio
will by default spawn one for each CPU core. The blocking threads are
spawned on demand, can be used to run blocking code that would otherwise
block other tasks from running and are kept alive when not used for a certain
amount of time which can be configured with <a href="runtime/struct.Builder.html#method.thread_keep_alive"><code>thread_keep_alive</code></a>.
Since it is not possible for Tokio to swap out blocking tasks, like it
can do with asynchronous code, the upper limit on the number of blocking
threads is very large. These limits can be configured on the <a href="runtime/struct.Builder.html"><code>Builder</code></a>.</p>
<p>To spawn a blocking task, you should use the <a href="task/fn.spawn_blocking.html"><code>spawn_blocking</code></a> function.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[<span class="ident">tokio::main</span>]</span>
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">main</span>() {
<span class="comment">// This is running on a core thread.</span>
<span class="kw">let</span> <span class="ident">blocking_task</span> <span class="op">=</span> <span class="ident">tokio::task::spawn_blocking</span>(<span class="op">|</span><span class="op">|</span> {
<span class="comment">// This is running on a blocking thread.</span>
<span class="comment">// Blocking here is ok.</span>
});
<span class="comment">// We can wait for the blocking task like this:</span>
<span class="comment">// If the blocking task panics, the unwrap below will propagate the</span>
<span class="comment">// panic.</span>
<span class="ident">blocking_task</span>.<span class="kw">await</span>.<span class="ident">unwrap</span>();
}</code></pre></div>
<p>If your code is CPU-bound and you wish to limit the number of threads used
to run it, you should use a separate thread pool dedicated to CPU bound tasks.
For example, you could consider using the <a href="https://docs.rs/rayon">rayon</a> library for CPU-bound
tasks. It is also possible to create an extra Tokio runtime dedicated to
CPU-bound tasks, but if you do this, you should be careful that the extra
runtime runs <em>only</em> CPU-bound tasks, as IO-bound tasks on that runtime
will behave poorly.</p>
<p>Hint: If using rayon, you can use a <a href="crate::sync::oneshot"><code>oneshot</code></a> channel to send the result back
to Tokio when the rayon task finishes.</p>
<h3 id="asynchronous-io" class="section-header"><a href="#asynchronous-io">Asynchronous IO</a></h3>
<p>As well as scheduling and running tasks, Tokio provides everything you need
to perform input and output asynchronously.</p>
<p>The <a href="io/index.html"><code>tokio::io</code></a> module provides Tokios asynchronous core I/O primitives,
the <a href="io/trait.AsyncRead.html"><code>AsyncRead</code></a>, <a href="io/trait.AsyncWrite.html"><code>AsyncWrite</code></a>, and <a href="io/trait.AsyncBufRead.html"><code>AsyncBufRead</code></a> traits. In addition,
when the “io-util” feature flag is enabled, it also provides combinators and
functions for working with these traits, forming as an asynchronous
counterpart to <a href="https://doc.rust-lang.org/1.59.0/std/io/index.html"><code>std::io</code></a>.</p>
<p>Tokio also includes APIs for performing various kinds of I/O and interacting
with the operating system asynchronously. These include:</p>
<ul>
<li><a href="net/index.html"><code>tokio::net</code></a>, which contains non-blocking versions of <a href="crate::net::tcp">TCP</a>, <a href="crate::net::UdpSocket">UDP</a>, and
<a href="crate::net::unix">Unix Domain Sockets</a> (enabled by the “net” feature flag),</li>
<li><a href="crate::fs"><code>tokio::fs</code></a>, similar to <a href="https://doc.rust-lang.org/1.59.0/std/fs/index.html"><code>std::fs</code></a> but for performing filesystem I/O
asynchronously (enabled by the “fs” feature flag),</li>
<li><a href="crate::signal"><code>tokio::signal</code></a>, for asynchronously handling Unix and Windows OS signals
(enabled by the “signal” feature flag),</li>
<li><a href="crate::process"><code>tokio::process</code></a>, for spawning and managing child processes (enabled by
the “process” feature flag).</li>
</ul>
<h2 id="examples" class="section-header"><a href="#examples">Examples</a></h2>
<p>A simple TCP echo server:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">tokio::net::TcpListener</span>;
<span class="kw">use</span> <span class="ident">tokio::io</span>::{<span class="ident">AsyncReadExt</span>, <span class="ident">AsyncWriteExt</span>};
<span class="attribute">#[<span class="ident">tokio::main</span>]</span>
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">main</span>() -&gt; <span class="prelude-ty">Result</span><span class="op">&lt;</span>(), <span class="ident">Box</span><span class="op">&lt;</span><span class="kw">dyn</span> <span class="ident">std::error::Error</span><span class="op">&gt;</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="ident">listener</span> <span class="op">=</span> <span class="ident">TcpListener::bind</span>(<span class="string">&quot;127.0.0.1:8080&quot;</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop</span> {
<span class="kw">let</span> (<span class="kw-2">mut</span> <span class="ident">socket</span>, <span class="kw">_</span>) <span class="op">=</span> <span class="ident">listener</span>.<span class="ident">accept</span>().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="ident">tokio::spawn</span>(<span class="kw">async</span> <span class="kw">move</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buf</span> <span class="op">=</span> [<span class="number">0</span>; <span class="number">1024</span>];
<span class="comment">// In a loop, read data from the socket and write the data back.</span>
<span class="kw">loop</span> {
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="kw">match</span> <span class="ident">socket</span>.<span class="ident">read</span>(<span class="kw-2">&amp;mut</span> <span class="ident">buf</span>).<span class="kw">await</span> {
<span class="comment">// socket closed</span>
<span class="prelude-val">Ok</span>(<span class="ident">n</span>) <span class="kw">if</span> <span class="ident">n</span> <span class="op">==</span> <span class="number">0</span> =&gt; <span class="kw">return</span>,
<span class="prelude-val">Ok</span>(<span class="ident">n</span>) =&gt; <span class="ident">n</span>,
<span class="prelude-val">Err</span>(<span class="ident">e</span>) =&gt; {
<span class="macro">eprintln!</span>(<span class="string">&quot;failed to read from socket; err = {:?}&quot;</span>, <span class="ident">e</span>);
<span class="kw">return</span>;
}
};
<span class="comment">// Write the data back</span>
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Err</span>(<span class="ident">e</span>) <span class="op">=</span> <span class="ident">socket</span>.<span class="ident">write_all</span>(<span class="kw-2">&amp;</span><span class="ident">buf</span>[<span class="number">0</span>..<span class="ident">n</span>]).<span class="kw">await</span> {
<span class="macro">eprintln!</span>(<span class="string">&quot;failed to write to socket; err = {:?}&quot;</span>, <span class="ident">e</span>);
<span class="kw">return</span>;
}
}
});
}
}</code></pre></div>
<h3 id="feature-flags" class="section-header"><a href="#feature-flags">Feature flags</a></h3>
<p>Tokio uses a set of <a href="https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section">feature flags</a> to reduce the amount of compiled code. It
is possible to just enable certain features over others. By default, Tokio
does not enable any features but allows one to enable a subset for their use
case. Below is a list of the available feature flags. You may also notice
above each function, struct and trait there is listed one or more feature flags
that are required for that item to be used. If you are new to Tokio it is
recommended that you use the <code>full</code> feature flag which will enable all public APIs.
Beware though that this will pull in many extra dependencies that you may not
need.</p>
<ul>
<li><code>full</code>: Enables all features listed below except <code>test-util</code> and <code>tracing</code>.</li>
<li><code>rt</code>: Enables <code>tokio::spawn</code>, the basic (current thread) scheduler,
and non-scheduler utilities.</li>
<li><code>rt-multi-thread</code>: Enables the heavier, multi-threaded, work-stealing scheduler.</li>
<li><code>io-util</code>: Enables the IO based <code>Ext</code> traits.</li>
<li><code>io-std</code>: Enable <code>Stdout</code>, <code>Stdin</code> and <code>Stderr</code> types.</li>
<li><code>net</code>: Enables <code>tokio::net</code> types such as <code>TcpStream</code>, <code>UnixStream</code> and
<code>UdpSocket</code>, as well as (on Unix-like systems) <code>AsyncFd</code> and (on
FreeBSD) <code>PollAio</code>.</li>
<li><code>time</code>: Enables <code>tokio::time</code> types and allows the schedulers to enable
the built in timer.</li>
<li><code>process</code>: Enables <code>tokio::process</code> types.</li>
<li><code>macros</code>: Enables <code>#[tokio::main]</code> and <code>#[tokio::test]</code> macros.</li>
<li><code>sync</code>: Enables all <code>tokio::sync</code> types.</li>
<li><code>signal</code>: Enables all <code>tokio::signal</code> types.</li>
<li><code>fs</code>: Enables <code>tokio::fs</code> types.</li>
<li><code>test-util</code>: Enables testing based infrastructure for the Tokio runtime.</li>
</ul>
<p><em>Note: <code>AsyncRead</code> and <code>AsyncWrite</code> traits do not require any features and are
always available.</em></p>
<h4 id="internal-features" class="section-header"><a href="#internal-features">Internal features</a></h4>
<p>These features do not expose any new API, but influence internal
implementation aspects of Tokio, and can pull in additional
dependencies.</p>
<ul>
<li><code>parking_lot</code>: As a potential optimization, use the <em>parking_lot</em> crates
synchronization primitives internally. MSRV may increase according to the
<em>parking_lot</em> release in use.</li>
</ul>
<h4 id="unstable-features" class="section-header"><a href="#unstable-features">Unstable features</a></h4>
<p>These feature flags enable <strong>unstable</strong> features. The public API may break in 1.x
releases. To enable these features, the <code>--cfg tokio_unstable</code> must be passed to
<code>rustc</code> when compiling. This is easiest done using the <code>RUSTFLAGS</code> env variable:
<code>RUSTFLAGS=&quot;--cfg tokio_unstable&quot;</code>.</p>
<ul>
<li><code>tracing</code>: Enables tracing events.</li>
</ul>
</div></details><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2>
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="io/index.html" title="tokio::io mod">io</a></div><div class="item-right docblock-short"><p>Traits, helpers, and type definitions for asynchronous I/O functionality.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="net/index.html" title="tokio::net mod">net</a></div><div class="item-right docblock-short"><p>TCP/UDP/Unix bindings for <code>tokio</code>.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="runtime/index.html" title="tokio::runtime mod">runtime</a></div><div class="item-right docblock-short"><p>The Tokio runtime.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="stream/index.html" title="tokio::stream mod">stream</a></div><div class="item-right docblock-short"><p>Due to the <code>Stream</code> traits inclusion in <code>std</code> landing later than Tokios 1.0
release, most of the Tokio stream utilities have been moved into the <a href="https://docs.rs/tokio-stream"><code>tokio-stream</code></a>
crate.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="task/index.html" title="tokio::task mod">task</a></div><div class="item-right docblock-short"><p>Asynchronous green-threads.</p>
</div></div></div><h2 id="macros" class="small-section-header"><a href="#macros">Macros</a></h2>
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.join.html" title="tokio::join macro">join</a></div><div class="item-right docblock-short"><p>Waits on multiple concurrent branches, returning when <strong>all</strong> branches
complete.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.pin.html" title="tokio::pin macro">pin</a></div><div class="item-right docblock-short"><p>Pins a value on the stack.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.select.html" title="tokio::select macro">select</a></div><div class="item-right docblock-short"><p>Waits on multiple concurrent branches, returning when the <strong>first</strong> branch
completes, cancelling the remaining branches.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.task_local.html" title="tokio::task_local macro">task_local</a></div><div class="item-right docblock-short"><p>Declares a new task-local key of type <a href="task/struct.LocalKey.html"><code>tokio::task::LocalKey</code></a>.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.try_join.html" title="tokio::try_join macro">try_join</a></div><div class="item-right docblock-short"><p>Waits on multiple concurrent branches, returning when <strong>all</strong> branches
complete with <code>Ok(_)</code> or on the first <code>Err(_)</code>.</p>
</div></div></div><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2>
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.spawn.html" title="tokio::spawn fn">spawn</a></div><div class="item-right docblock-short"><p>Spawns a new asynchronous task, returning a
<a href="task/struct.JoinHandle.html"><code>JoinHandle</code></a> for it.</p>
</div></div></div><h2 id="attributes" class="small-section-header"><a href="#attributes">Attribute Macros</a></h2>
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="attr" href="attr.main.html" title="tokio::main attr">main</a></div><div class="item-right docblock-short"><p>Marks async function to be executed by the selected runtime. This macro
helps set up a <code>Runtime</code> without requiring the user to use
<a href="../tokio/runtime/struct.Runtime.html">Runtime</a> or
<a href="../tokio/runtime/struct.Builder.html">Builder</a> directly.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="attr" href="attr.test.html" title="tokio::test attr">test</a></div><div class="item-right docblock-short"><p>Marks async function to be executed by runtime, suitable to test environment</p>
</div></div></div></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="tokio" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.59.0 (9d1b2106e 2022-02-23)" ></div>
</body></html>