Files
google-apis-rs/futures/task/trait.SpawnExt.html
2024-03-05 21:06:01 +01:00

54 lines
13 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 `Spawn`."><title>SpawnExt in futures::task - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="futures" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../futures/index.html">futures</a><span class="version">0.3.28</span></h2></div><h2 class="location"><a href="#">SpawnExt</a></h2><div class="sidebar-elems"><section><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.spawn">spawn</a></li><li><a href="#method.spawn_with_handle">spawn_with_handle</a></li></ul><h3><a href="#object-safety">Object Safety</a></h3><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In futures::task</a></h2></div></nav><div class="sidebar-resizer"></div>
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../../futures/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Trait <a href="../index.html">futures</a>::<wbr><a href="index.html">task</a>::<wbr><a class="trait" href="#">SpawnExt</a><button id="copy-path" title="Copy item path to clipboard"><img src="../../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../../src/futures_util/task/spawn.rs.html#20">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><pre class="rust item-decl"><code>pub trait SpawnExt: <a class="trait" href="trait.Spawn.html" title="trait futures::task::Spawn">Spawn</a> {
// Provided methods
fn <a href="#method.spawn" class="fn">spawn</a>&lt;Fut&gt;(&amp;self, future: Fut) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>, <a class="struct" href="struct.SpawnError.html" title="struct futures::task::SpawnError">SpawnError</a>&gt;
<span class="where">where Fut: <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a>&lt;Output = <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static</span> { ... }
<span class="item-spacer"></span> fn <a href="#method.spawn_with_handle" class="fn">spawn_with_handle</a>&lt;Fut&gt;(
&amp;self,
future: Fut
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../future/struct.RemoteHandle.html" title="struct futures::future::RemoteHandle">RemoteHandle</a>&lt;&lt;Fut as <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a>&gt;::<a class="associatedtype" href="../future/trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>&gt;, <a class="struct" href="struct.SpawnError.html" title="struct futures::task::SpawnError">SpawnError</a>&gt;
<span class="where">where Fut: <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static,
&lt;Fut as <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a>&gt;::<a class="associatedtype" href="../future/trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></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>Spawn</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" class="method"><a class="src rightside" href="../../src/futures_util/task/spawn.rs.html#49-51">source</a><h4 class="code-header">fn <a href="#method.spawn" class="fn">spawn</a>&lt;Fut&gt;(&amp;self, future: Fut) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>, <a class="struct" href="struct.SpawnError.html" title="struct futures::task::SpawnError">SpawnError</a>&gt;<div class="where">where
Fut: <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a>&lt;Output = <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + '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.76.0/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::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::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::ThreadPool;
<span class="kw">use </span>futures::task::SpawnExt;
<span class="kw">let </span>executor = ThreadPool::new().unwrap();
<span class="kw">let </span>future = <span class="kw">async </span>{ <span class="comment">/* ... */ </span>};
executor.spawn(future).unwrap();</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.spawn_with_handle" class="method"><a class="src rightside" href="../../src/futures_util/task/spawn.rs.html#80-83">source</a><h4 class="code-header">fn <a href="#method.spawn_with_handle" class="fn">spawn_with_handle</a>&lt;Fut&gt;(
&amp;self,
future: Fut
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../future/struct.RemoteHandle.html" title="struct futures::future::RemoteHandle">RemoteHandle</a>&lt;&lt;Fut as <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a>&gt;::<a class="associatedtype" href="../future/trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>&gt;, <a class="struct" href="struct.SpawnError.html" title="struct futures::task::SpawnError">SpawnError</a>&gt;<div class="where">where
Fut: <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static,
&lt;Fut as <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a>&gt;::<a class="associatedtype" href="../future/trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,</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.76.0/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::future::RemoteHandle"><code>RemoteHandle</code></a>, or, if
spawning fails, a <a href="struct.SpawnError.html" title="struct futures::task::SpawnError"><code>SpawnError</code></a>. <a href="../future/struct.RemoteHandle.html" title="struct futures::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::{block_on, ThreadPool};
<span class="kw">use </span>futures::future;
<span class="kw">use </span>futures::task::SpawnExt;
<span class="kw">let </span>executor = ThreadPool::new().unwrap();
<span class="kw">let </span>future = future::ready(<span class="number">1</span>);
<span class="kw">let </span>join_handle_fut = executor.spawn_with_handle(future).unwrap();
<span class="macro">assert_eq!</span>(block_on(join_handle_fut), <span class="number">1</span>);</code></pre></div>
</div></details></div><h2 id="object-safety" class="section-header">Object Safety<a href="#object-safety" class="anchor">§</a></h2><div class="object-safety-info">This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.76.0/reference/items/traits.html#object-safety">object safe</a>.</div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-SpawnExt-for-Sp" class="impl"><a class="src rightside" href="../../src/futures_util/task/spawn.rs.html#16">source</a><a href="#impl-SpawnExt-for-Sp" class="anchor">§</a><h3 class="code-header">impl&lt;Sp&gt; <a class="trait" href="trait.SpawnExt.html" title="trait futures::task::SpawnExt">SpawnExt</a> for Sp<div class="where">where
Sp: <a class="trait" href="trait.Spawn.html" title="trait futures::task::Spawn">Spawn</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/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.SpawnExt.js" async></script></section></div></main></body></html>