| <!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="Builds Tokio Runtime with custom configuration values."><meta name="keywords" content="rust, rustlang, rust-lang, Builder"><title>Builder in tokio::runtime - 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" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="sidebar-items.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 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">☰</button><a class="sidebar-logo" href="../../tokio/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../tokio/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Builder</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.build">build</a></li><li><a href="#method.enable_all">enable_all</a></li><li><a href="#method.enable_io">enable_io</a></li><li><a href="#method.enable_time">enable_time</a></li><li><a href="#method.event_interval">event_interval</a></li><li><a href="#method.global_queue_interval">global_queue_interval</a></li><li><a href="#method.max_blocking_threads">max_blocking_threads</a></li><li><a href="#method.max_io_events_per_tick">max_io_events_per_tick</a></li><li><a href="#method.new_current_thread">new_current_thread</a></li><li><a href="#method.on_thread_park">on_thread_park</a></li><li><a href="#method.on_thread_start">on_thread_start</a></li><li><a href="#method.on_thread_stop">on_thread_stop</a></li><li><a href="#method.on_thread_unpark">on_thread_unpark</a></li><li><a href="#method.thread_keep_alive">thread_keep_alive</a></li><li><a href="#method.thread_name">thread_name</a></li><li><a href="#method.thread_name_fn">thread_name_fn</a></li><li><a href="#method.thread_stack_size">thread_stack_size</a></li><li><a href="#method.worker_threads">worker_threads</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-Debug-for-Builder">Debug</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-Builder">!RefUnwindSafe</a></li><li><a href="#impl-Send-for-Builder">Send</a></li><li><a href="#impl-Sync-for-Builder">Sync</a></li><li><a href="#impl-Unpin-for-Builder">Unpin</a></li><li><a href="#impl-UnwindSafe-for-Builder">!UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-Builder">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-Builder">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-Builder">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-Builder">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-Builder">Into<U></a></li><li><a href="#impl-TryFrom%3CU%3E-for-Builder">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-Builder">TryInto<U></a></li></ul></section><h2><a href="index.html">In tokio::runtime</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Struct <a href="../index.html">tokio</a>::<wbr><a href="index.html">runtime</a>::<wbr><a class="struct" href="#">Builder</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></h1><span class="out-of-band"><a class="srclink" href="../../src/tokio/runtime/builder.rs.html#41-100">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct Builder { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Builds Tokio Runtime with custom configuration values.</p> |
| <p>Methods can be chained in order to set the configuration values. The |
| Runtime is constructed by calling <a href="struct.Builder.html#method.build"><code>build</code></a>.</p> |
| <p>New instances of <code>Builder</code> are obtained via <a href="method@Self::new_multi_thread"><code>Builder::new_multi_thread</code></a> |
| or <a href="struct.Builder.html#method.new_current_thread"><code>Builder::new_current_thread</code></a>.</p> |
| <p>See function level documentation for details on the various configuration |
| settings.</p> |
| <h2 id="examples"><a href="#examples">Examples</a></h2> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::runtime::Builder; |
| |
| <span class="kw">fn </span>main() { |
| <span class="comment">// build runtime |
| </span><span class="kw">let </span>runtime = Builder::new_multi_thread() |
| .worker_threads(<span class="number">4</span>) |
| .thread_name(<span class="string">"my-custom-name"</span>) |
| .thread_stack_size(<span class="number">3 </span>* <span class="number">1024 </span>* <span class="number">1024</span>) |
| .build() |
| .unwrap(); |
| |
| <span class="comment">// use runtime ... |
| </span>}</code></pre></div> |
| </div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Builder" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#192-925">source</a><a href="#impl-Builder" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.Builder.html" title="struct tokio::runtime::Builder">Builder</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.new_current_thread" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#201-209">source</a><h4 class="code-header">pub fn <a href="#method.new_current_thread" class="fnname">new_current_thread</a>() -> <a class="struct" href="struct.Builder.html" title="struct tokio::runtime::Builder">Builder</a></h4></section></summary><div class="docblock"><p>Returns a new builder with the current thread scheduler selected.</p> |
| <p>Configuration methods can be chained on the return value.</p> |
| <p>To spawn non-<code>Send</code> tasks on the resulting runtime, combine it with a |
| <a href="../task/struct.LocalSet.html"><code>LocalSet</code></a>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.enable_all" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#291-302">source</a><h4 class="code-header">pub fn <a href="#method.enable_all" class="fnname">enable_all</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Enables both I/O and time drivers.</p> |
| <p>Doing this is a shorthand for calling <code>enable_io</code> and <code>enable_time</code> |
| individually. If additional components are added to Tokio in the future, |
| <code>enable_all</code> will include these future components.</p> |
| <h5 id="examples-1"><a href="#examples-1">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::runtime; |
| |
| <span class="kw">let </span>rt = runtime::Builder::new_multi_thread() |
| .enable_all() |
| .build() |
| .unwrap();</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.worker_threads" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#352-356">source</a><h4 class="code-header">pub fn <a href="#method.worker_threads" class="fnname">worker_threads</a>(&mut self, val: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Sets the number of worker threads the <code>Runtime</code> will use.</p> |
| <p>This can be any number above 0 though it is advised to keep this value |
| on the smaller side.</p> |
| <p>This will override the value read from environment variable <code>TOKIO_WORKER_THREADS</code>.</p> |
| <h5 id="default"><a href="#default">Default</a></h5> |
| <p>The default value is the number of cores available to the system.</p> |
| <p>When using the <code>current_thread</code> runtime this method has no effect.</p> |
| <h5 id="examples-2"><a href="#examples-2">Examples</a></h5><h6 id="multi-threaded-runtime-with-4-threads"><a href="#multi-threaded-runtime-with-4-threads">Multi threaded runtime with 4 threads</a></h6> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::runtime; |
| |
| <span class="comment">// This will spawn a work-stealing runtime with 4 worker threads. |
| </span><span class="kw">let </span>rt = runtime::Builder::new_multi_thread() |
| .worker_threads(<span class="number">4</span>) |
| .build() |
| .unwrap(); |
| |
| rt.spawn(<span class="kw">async move </span>{});</code></pre></div> |
| <h6 id="current-thread-runtime-will-only-run-on-the-current-thread-via-runtimeblock_on"><a href="#current-thread-runtime-will-only-run-on-the-current-thread-via-runtimeblock_on">Current thread runtime (will only run on the current thread via <code>Runtime::block_on</code>)</a></h6> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::runtime; |
| |
| <span class="comment">// Create a runtime that _must_ be driven from a call |
| // to `Runtime::block_on`. |
| </span><span class="kw">let </span>rt = runtime::Builder::new_current_thread() |
| .build() |
| .unwrap(); |
| |
| <span class="comment">// This will run the runtime and future on the current thread |
| </span>rt.block_on(<span class="kw">async move </span>{});</code></pre></div> |
| <h5 id="panics"><a href="#panics">Panics</a></h5> |
| <p>This will panic if <code>val</code> is not larger than <code>0</code>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.max_blocking_threads" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#381-385">source</a><h4 class="code-header">pub fn <a href="#method.max_blocking_threads" class="fnname">max_blocking_threads</a>(&mut self, val: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Specifies the limit for additional threads spawned by the Runtime.</p> |
| <p>These threads are used for blocking operations like tasks spawned |
| through <a href="../task/fn.spawn_blocking.html"><code>spawn_blocking</code></a>. Unlike the <a href="struct.Builder.html#method.worker_threads"><code>worker_threads</code></a>, they are not |
| always active and will exit if left idle for too long. You can change |
| this timeout duration with <a href="struct.Builder.html#method.thread_keep_alive"><code>thread_keep_alive</code></a>.</p> |
| <p>The default value is 512.</p> |
| <h5 id="panics-1"><a href="#panics-1">Panics</a></h5> |
| <p>This will panic if <code>val</code> is not larger than <code>0</code>.</p> |
| <h5 id="upgrading-from-0x"><a href="#upgrading-from-0x">Upgrading from 0.x</a></h5> |
| <p>In old versions <code>max_threads</code> limited both blocking and worker threads, but the |
| current <code>max_blocking_threads</code> does not include async worker threads in the count.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.thread_name" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#402-406">source</a><h4 class="code-header">pub fn <a href="#method.thread_name" class="fnname">thread_name</a>(&mut self, val: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Sets name of threads spawned by the <code>Runtime</code>’s thread pool.</p> |
| <p>The default name is “tokio-runtime-worker”.</p> |
| <h5 id="examples-3"><a href="#examples-3">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code> |
| <span class="kw">let </span>rt = runtime::Builder::new_multi_thread() |
| .thread_name(<span class="string">"my-pool"</span>) |
| .build();</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.thread_name_fn" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#427-433">source</a><h4 class="code-header">pub fn <a href="#method.thread_name_fn" class="fnname">thread_name_fn</a><F>(&mut self, f: F) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self<span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static,</span></h4></section></summary><div class="docblock"><p>Sets a function used to generate the name of threads spawned by the <code>Runtime</code>’s thread pool.</p> |
| <p>The default name fn is <code>|| "tokio-runtime-worker".into()</code>.</p> |
| <h5 id="examples-4"><a href="#examples-4">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>rt = runtime::Builder::new_multi_thread() |
| .thread_name_fn(|| { |
| <span class="kw">static </span>ATOMIC_ID: AtomicUsize = AtomicUsize::new(<span class="number">0</span>); |
| <span class="kw">let </span>id = ATOMIC_ID.fetch_add(<span class="number">1</span>, Ordering::SeqCst); |
| <span class="macro">format!</span>(<span class="string">"my-pool-{}"</span>, id) |
| }) |
| .build();</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.thread_stack_size" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#454-457">source</a><h4 class="code-header">pub fn <a href="#method.thread_stack_size" class="fnname">thread_stack_size</a>(&mut self, val: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Sets the stack size (in bytes) for worker threads.</p> |
| <p>The actual stack size may be greater than this value if the platform |
| specifies minimal stack size.</p> |
| <p>The default stack size for spawned threads is 2 MiB, though this |
| particular stack size is subject to change in the future.</p> |
| <h5 id="examples-5"><a href="#examples-5">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code> |
| <span class="kw">let </span>rt = runtime::Builder::new_multi_thread() |
| .thread_stack_size(<span class="number">32 </span>* <span class="number">1024</span>) |
| .build();</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.on_thread_start" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#477-483">source</a><h4 class="code-header">pub fn <a href="#method.on_thread_start" class="fnname">on_thread_start</a><F>(&mut self, f: F) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self<span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static,</span></h4></section></summary><div class="docblock"><p>Executes function <code>f</code> after each thread is started but before it starts |
| doing work.</p> |
| <p>This is intended for bookkeeping and monitoring use cases.</p> |
| <h5 id="examples-6"><a href="#examples-6">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>runtime = runtime::Builder::new_multi_thread() |
| .on_thread_start(|| { |
| <span class="macro">println!</span>(<span class="string">"thread started"</span>); |
| }) |
| .build();</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.on_thread_stop" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#502-508">source</a><h4 class="code-header">pub fn <a href="#method.on_thread_stop" class="fnname">on_thread_stop</a><F>(&mut self, f: F) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self<span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static,</span></h4></section></summary><div class="docblock"><p>Executes function <code>f</code> before each thread stops.</p> |
| <p>This is intended for bookkeeping and monitoring use cases.</p> |
| <h5 id="examples-7"><a href="#examples-7">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>runtime = runtime::Builder::new_multi_thread() |
| .on_thread_stop(|| { |
| <span class="macro">println!</span>(<span class="string">"thread stopping"</span>); |
| }) |
| .build();</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.on_thread_park" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#580-586">source</a><h4 class="code-header">pub fn <a href="#method.on_thread_park" class="fnname">on_thread_park</a><F>(&mut self, f: F) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self<span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static,</span></h4></section></summary><div class="docblock"><p>Executes function <code>f</code> just before a thread is parked (goes idle). |
| <code>f</code> is called within the Tokio context, so functions like <a href="../task/fn.spawn.html"><code>tokio::spawn</code></a> |
| can be called, and may result in this thread being unparked immediately.</p> |
| <p>This can be used to start work only when the executor is idle, or for bookkeeping |
| and monitoring purposes.</p> |
| <p>Note: There can only be one park callback for a runtime; calling this function |
| more than once replaces the last callback defined, rather than adding to it.</p> |
| <h5 id="examples-8"><a href="#examples-8">Examples</a></h5><h6 id="multithreaded-executor"><a href="#multithreaded-executor">Multithreaded executor</a></h6> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>once = AtomicBool::new(<span class="bool-val">true</span>); |
| <span class="kw">let </span>barrier = Arc::new(Barrier::new(<span class="number">2</span>)); |
| |
| <span class="kw">let </span>runtime = runtime::Builder::new_multi_thread() |
| .worker_threads(<span class="number">1</span>) |
| .on_thread_park({ |
| <span class="kw">let </span>barrier = barrier.clone(); |
| <span class="kw">move </span>|| { |
| <span class="kw">let </span>barrier = barrier.clone(); |
| <span class="kw">if </span>once.swap(<span class="bool-val">false</span>, Ordering::Relaxed) { |
| tokio::spawn(<span class="kw">async move </span>{ barrier.wait().<span class="kw">await</span>; }); |
| } |
| } |
| }) |
| .build() |
| .unwrap(); |
| |
| runtime.block_on(<span class="kw">async </span>{ |
| barrier.wait().<span class="kw">await</span>; |
| })</code></pre></div> |
| <h6 id="current-thread-executor"><a href="#current-thread-executor">Current thread executor</a></h6> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>once = AtomicBool::new(<span class="bool-val">true</span>); |
| <span class="kw">let </span>barrier = Arc::new(Barrier::new(<span class="number">2</span>)); |
| |
| <span class="kw">let </span>runtime = runtime::Builder::new_current_thread() |
| .on_thread_park({ |
| <span class="kw">let </span>barrier = barrier.clone(); |
| <span class="kw">move </span>|| { |
| <span class="kw">let </span>barrier = barrier.clone(); |
| <span class="kw">if </span>once.swap(<span class="bool-val">false</span>, Ordering::Relaxed) { |
| tokio::spawn(<span class="kw">async move </span>{ barrier.wait().<span class="kw">await</span>; }); |
| } |
| } |
| }) |
| .build() |
| .unwrap(); |
| |
| runtime.block_on(<span class="kw">async </span>{ |
| barrier.wait().<span class="kw">await</span>; |
| })</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.on_thread_unpark" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#615-621">source</a><h4 class="code-header">pub fn <a href="#method.on_thread_unpark" class="fnname">on_thread_unpark</a><F>(&mut self, f: F) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self<span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static,</span></h4></section></summary><div class="docblock"><p>Executes function <code>f</code> just after a thread unparks (starts executing tasks).</p> |
| <p>This is intended for bookkeeping and monitoring use cases; note that work |
| in this callback will increase latencies when the application has allowed one or |
| more runtime threads to go idle.</p> |
| <p>Note: There can only be one unpark callback for a runtime; calling this function |
| more than once replaces the last callback defined, rather than adding to it.</p> |
| <h5 id="examples-9"><a href="#examples-9">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>runtime = runtime::Builder::new_multi_thread() |
| .on_thread_unpark(|| { |
| <span class="macro">println!</span>(<span class="string">"thread unparking"</span>); |
| }) |
| .build(); |
| |
| runtime.unwrap().block_on(<span class="kw">async </span>{ |
| tokio::task::yield_now().<span class="kw">await</span>; |
| <span class="macro">println!</span>(<span class="string">"Hello from Tokio!"</span>); |
| })</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.build" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#638-644">source</a><h4 class="code-header">pub fn <a href="#method.build" class="fnname">build</a>(&mut self) -> <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="struct.Runtime.html" title="struct tokio::runtime::Runtime">Runtime</a>></h4></section></summary><div class="docblock"><p>Creates the configured <code>Runtime</code>.</p> |
| <p>The returned <code>Runtime</code> instance is ready to spawn tasks.</p> |
| <h5 id="examples-10"><a href="#examples-10">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::runtime::Builder; |
| |
| <span class="kw">let </span>rt = Builder::new_multi_thread().build().unwrap(); |
| |
| rt.block_on(<span class="kw">async </span>{ |
| <span class="macro">println!</span>(<span class="string">"Hello from the Tokio runtime"</span>); |
| });</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.thread_keep_alive" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#676-679">source</a><h4 class="code-header">pub fn <a href="#method.thread_keep_alive" class="fnname">thread_keep_alive</a>(&mut self, duration: <a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Sets a custom timeout for a thread in the blocking pool.</p> |
| <p>By default, the timeout for a thread is set to 10 seconds. This can |
| be overridden using .thread_keep_alive().</p> |
| <h5 id="example"><a href="#example">Example</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>rt = runtime::Builder::new_multi_thread() |
| .thread_keep_alive(Duration::from_millis(<span class="number">100</span>)) |
| .build();</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.global_queue_interval" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#708-711">source</a><h4 class="code-header">pub fn <a href="#method.global_queue_interval" class="fnname">global_queue_interval</a>(&mut self, val: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Sets the number of scheduler ticks after which the scheduler will poll the global |
| task queue.</p> |
| <p>A scheduler “tick” roughly corresponds to one <code>poll</code> invocation on a task.</p> |
| <p>By default the global queue interval is:</p> |
| <ul> |
| <li><code>31</code> for the current-thread scheduler.</li> |
| <li><code>61</code> for the multithreaded scheduler.</li> |
| </ul> |
| <p>Schedulers have a local queue of already-claimed tasks, and a global queue of incoming |
| tasks. Setting the interval to a smaller value increases the fairness of the scheduler, |
| at the cost of more synchronization overhead. That can be beneficial for prioritizing |
| getting started on new work, especially if tasks frequently yield rather than complete |
| or await on further I/O. Conversely, a higher value prioritizes existing work, and |
| is a good choice when most tasks quickly complete polling.</p> |
| <h5 id="examples-11"><a href="#examples-11">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>rt = runtime::Builder::new_multi_thread() |
| .global_queue_interval(<span class="number">31</span>) |
| .build();</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.event_interval" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#740-743">source</a><h4 class="code-header">pub fn <a href="#method.event_interval" class="fnname">event_interval</a>(&mut self, val: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Sets the number of scheduler ticks after which the scheduler will poll for |
| external events (timers, I/O, and so on).</p> |
| <p>A scheduler “tick” roughly corresponds to one <code>poll</code> invocation on a task.</p> |
| <p>By default, the event interval is <code>61</code> for all scheduler types.</p> |
| <p>Setting the event interval determines the effective “priority” of delivering |
| these external events (which may wake up additional tasks), compared to |
| executing tasks that are currently ready to run. A smaller value is useful |
| when tasks frequently spend a long time in polling, or frequently yield, |
| which can result in overly long delays picking up I/O events. Conversely, |
| picking up new events requires extra synchronization and syscall overhead, |
| so if tasks generally complete their polling quickly, a higher event interval |
| will minimize that overhead while still keeping the scheduler responsive to |
| events.</p> |
| <h5 id="examples-12"><a href="#examples-12">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>rt = runtime::Builder::new_multi_thread() |
| .event_interval(<span class="number">31</span>) |
| .build();</code></pre></div> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Builder-1" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#928-967">source</a><a href="#impl-Builder-1" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.Builder.html" title="struct tokio::runtime::Builder">Builder</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.enable_io" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#944-947">source</a><h4 class="code-header">pub fn <a href="#method.enable_io" class="fnname">enable_io</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Enables the I/O driver.</p> |
| <p>Doing this enables using net, process, signal, and some I/O types on |
| the runtime.</p> |
| <h5 id="examples-13"><a href="#examples-13">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::runtime; |
| |
| <span class="kw">let </span>rt = runtime::Builder::new_multi_thread() |
| .enable_io() |
| .build() |
| .unwrap();</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.max_io_events_per_tick" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#963-966">source</a><h4 class="code-header">pub fn <a href="#method.max_io_events_per_tick" class="fnname">max_io_events_per_tick</a>(&mut self, capacity: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Enables the I/O driver and configures the max number of events to be |
| processed per tick.</p> |
| <h5 id="examples-14"><a href="#examples-14">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::runtime; |
| |
| <span class="kw">let </span>rt = runtime::Builder::new_current_thread() |
| .enable_io() |
| .max_io_events_per_tick(<span class="number">1024</span>) |
| .build() |
| .unwrap();</code></pre></div> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Builder-2" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#971-990">source</a><a href="#impl-Builder-2" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.Builder.html" title="struct tokio::runtime::Builder">Builder</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.enable_time" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#986-989">source</a><h4 class="code-header">pub fn <a href="#method.enable_time" class="fnname">enable_time</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</h4></section></summary><div class="docblock"><p>Enables the time driver.</p> |
| <p>Doing this enables using <code>tokio::time</code> on the runtime.</p> |
| <h5 id="examples-15"><a href="#examples-15">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::runtime; |
| |
| <span class="kw">let </span>rt = runtime::Builder::new_multi_thread() |
| .enable_time() |
| .build() |
| .unwrap();</code></pre></div> |
| </div></details></div></details></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-Builder" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#1067-1083">source</a><a href="#impl-Debug-for-Builder" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.Builder.html" title="struct tokio::runtime::Builder">Builder</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/runtime/builder.rs.html#1068-1082">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&self, fmt: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-Builder" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-Builder" class="anchor"></a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Builder.html" title="struct tokio::runtime::Builder">Builder</a></h3></section><section id="impl-Send-for-Builder" class="impl has-srclink"><a href="#impl-Send-for-Builder" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.Builder.html" title="struct tokio::runtime::Builder">Builder</a></h3></section><section id="impl-Sync-for-Builder" class="impl has-srclink"><a href="#impl-Sync-for-Builder" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.Builder.html" title="struct tokio::runtime::Builder">Builder</a></h3></section><section id="impl-Unpin-for-Builder" class="impl has-srclink"><a href="#impl-Unpin-for-Builder" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Builder.html" title="struct tokio::runtime::Builder">Builder</a></h3></section><section id="impl-UnwindSafe-for-Builder" class="impl has-srclink"><a href="#impl-UnwindSafe-for-Builder" class="anchor"></a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Builder.html" title="struct tokio::runtime::Builder">Builder</a></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-Builder" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#200">source</a><a href="#impl-Any-for-Builder" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<span class="where fmt-newline">where<br> T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#201">source</a><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/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/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-Builder" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#211">source</a><a href="#impl-Borrow%3CT%3E-for-Builder" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#213">source</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-Builder" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#220">source</a><a href="#impl-BorrowMut%3CT%3E-for-Builder" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#221">source</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-Builder" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#733">source</a><a href="#impl-From%3CT%3E-for-Builder" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#736">source</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-Builder" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#717">source</a><a href="#impl-Into%3CU%3E-for-Builder" class="anchor"></a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#725">source</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into" class="fnname">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/nightly/core/convert/trait.From.html" title="From">From</a><T> for U</code> chooses to do.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-Builder" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#775">source</a><a href="#impl-TryFrom%3CU%3E-for-Builder" class="anchor"></a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/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="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#781">source</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/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="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-Builder" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#760">source</a><a href="#impl-TryInto%3CU%3E-for-Builder" class="anchor"></a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/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="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#766">source</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/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><div id="rustdoc-vars" data-root-path="../../" data-current-crate="tokio" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html> |