Files
GopherGate/target/doc/futures_util/task/trait.LocalSpawnExt.html
2026-02-26 12:00:21 -05:00

50 lines
12 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="Extension trait for `LocalSpawn`."><title>LocalSpawnExt in futures_util::task - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="futures_util" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">LocalSpawnExt</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../futures_util/index.html">futures_<wbr>util</a><span class="version">0.3.32</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Local<wbr>Spawn<wbr>Ext</a></h2><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.spawn_local" title="spawn_local">spawn_local</a></li><li><a href="#method.spawn_local_with_handle" title="spawn_local_with_handle">spawn_local_with_handle</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In futures_<wbr>util::<wbr>task</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">futures_util</a>::<wbr><a href="index.html">task</a></div><h1>Trait <span class="trait">Local<wbr>Spawn<wbr>Ext</span>&nbsp;<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/futures_util/task/spawn.rs.html#103-169">Source</a> </span></div><pre class="rust item-decl"><code>pub trait LocalSpawnExt: <a class="trait" href="trait.LocalSpawn.html" title="trait futures_util::task::LocalSpawn">LocalSpawn</a> {
// Provided methods
fn <a href="#method.spawn_local" class="fn">spawn_local</a>&lt;Fut&gt;(&amp;self, future: Fut) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>, <a class="struct" href="struct.SpawnError.html" title="struct futures_util::task::SpawnError">SpawnError</a>&gt;
<span class="where">where Fut: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>&lt;Output = <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt; + 'static</span> { ... }
<span class="item-spacer"></span> fn <a href="#method.spawn_local_with_handle" class="fn">spawn_local_with_handle</a>&lt;Fut&gt;(
&amp;self,
future: Fut,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../future/struct.RemoteHandle.html" title="struct futures_util::future::RemoteHandle">RemoteHandle</a>&lt;Fut::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>&gt;, <a class="struct" href="struct.SpawnError.html" title="struct futures_util::task::SpawnError">SpawnError</a>&gt;
<span class="where">where Fut: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> + 'static</span> { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extension trait for <code>LocalSpawn</code>.</p>
</div></details><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.spawn_local" class="method"><a class="src rightside" href="../../src/futures_util/task/spawn.rs.html#130-135">Source</a><h4 class="code-header">fn <a href="#method.spawn_local" class="fn">spawn_local</a>&lt;Fut&gt;(&amp;self, future: Fut) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>, <a class="struct" href="struct.SpawnError.html" title="struct futures_util::task::SpawnError">SpawnError</a>&gt;<div class="where">where
Fut: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>&lt;Output = <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt; + 'static,</div></h4></section></summary><div class="docblock"><p>Spawns a task that polls the given future with output <code>()</code> to
completion.</p>
<p>This method returns a <a href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result"><code>Result</code></a> that contains a <a href="struct.SpawnError.html" title="struct futures_util::task::SpawnError"><code>SpawnError</code></a> if
spawning fails.</p>
<p>You can use <a href="trait.SpawnExt.html#method.spawn_with_handle" title="method futures_util::task::SpawnExt::spawn_with_handle"><code>spawn_with_handle</code></a> if
you want to spawn a future with output other than <code>()</code> or if you want
to be able to await its completion.</p>
<p>Note this method will eventually be replaced with the upcoming
<code>Spawn::spawn</code> method which will take a <code>dyn Future</code> as input.
Technical limitations prevent <code>Spawn::spawn</code> from being implemented
today. Feel free to use this method in the meantime.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::executor::LocalPool;
<span class="kw">use </span>futures::task::LocalSpawnExt;
<span class="kw">let </span>executor = LocalPool::new();
<span class="kw">let </span>spawner = executor.spawner();
<span class="kw">let </span>future = <span class="kw">async </span>{ <span class="comment">/* ... */ </span>};
spawner.spawn_local(future).unwrap();</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.spawn_local_with_handle" class="method"><a class="src rightside" href="../../src/futures_util/task/spawn.rs.html#158-168">Source</a><h4 class="code-header">fn <a href="#method.spawn_local_with_handle" class="fn">spawn_local_with_handle</a>&lt;Fut&gt;(
&amp;self,
future: Fut,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../future/struct.RemoteHandle.html" title="struct futures_util::future::RemoteHandle">RemoteHandle</a>&lt;Fut::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>&gt;, <a class="struct" href="struct.SpawnError.html" title="struct futures_util::task::SpawnError">SpawnError</a>&gt;<div class="where">where
Fut: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> + 'static,</div></h4></section></summary><div class="docblock"><p>Spawns a task that polls the given future to completion and returns a
future that resolves to the spawned futures output.</p>
<p>This method returns a <a href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result"><code>Result</code></a> that contains a <a href="../future/struct.RemoteHandle.html" title="struct futures_util::future::RemoteHandle"><code>RemoteHandle</code></a>, or, if
spawning fails, a <a href="struct.SpawnError.html" title="struct futures_util::task::SpawnError"><code>SpawnError</code></a>. <a href="../future/struct.RemoteHandle.html" title="struct futures_util::future::RemoteHandle"><code>RemoteHandle</code></a> is a future that
resolves to the output of the spawned future.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::executor::LocalPool;
<span class="kw">use </span>futures::task::LocalSpawnExt;
<span class="kw">let </span><span class="kw-2">mut </span>executor = LocalPool::new();
<span class="kw">let </span>spawner = executor.spawner();
<span class="kw">let </span>future = <span class="kw">async </span>{ <span class="number">1 </span>};
<span class="kw">let </span>join_handle_fut = spawner.spawn_local_with_handle(future).unwrap();
<span class="macro">assert_eq!</span>(executor.run_until(join_handle_fut), <span class="number">1</span>);</code></pre></div></div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.93.1/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-LocalSpawnExt-for-Sp" class="impl"><a class="src rightside" href="../../src/futures_util/task/spawn.rs.html#17">Source</a><a href="#impl-LocalSpawnExt-for-Sp" class="anchor">§</a><h3 class="code-header">impl&lt;Sp&gt; <a class="trait" href="trait.LocalSpawnExt.html" title="trait futures_util::task::LocalSpawnExt">LocalSpawnExt</a> for Sp<div class="where">where
Sp: <a class="trait" href="trait.LocalSpawn.html" title="trait futures_util::task::LocalSpawn">LocalSpawn</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></div><script src="../../trait.impl/futures_util/task/spawn/trait.LocalSpawnExt.js" async></script></section></div></main></body></html>