31 lines
7.3 KiB
HTML
31 lines
7.3 KiB
HTML
<!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="Creates a new task without `Send`, `Sync`, and `'static` bounds."><title>spawn_unchecked in async_task - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="async_task" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="icon" href="https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../async_task/index.html"><img src="https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../async_task/index.html"><img src="https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png" alt="logo"></a><h2><a href="../async_task/index.html">async_<wbr>task</a><span class="version">4.7.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">spawn_<wbr>unchecked</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#safety" title="Safety">Safety</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate async_<wbr>task</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">async_task</a></span><h1>Function <span class="fn">spawn_unchecked</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/async_task/runnable.rs.html#648-654">Source</a> </span></div><pre class="rust item-decl"><code>pub unsafe fn spawn_unchecked<F, S>(
|
||
future: F,
|
||
schedule: S,
|
||
) -> (<a class="struct" href="struct.Runnable.html" title="struct async_task::Runnable">Runnable</a>, <a class="struct" href="struct.Task.html" title="struct async_task::Task">Task</a><F::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.0/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>)<div class="where">where
|
||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,
|
||
S: <a class="trait" href="trait.Schedule.html" title="trait async_task::Schedule">Schedule</a>,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates a new task without <a href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Send.html" title="trait core::marker::Send"><code>Send</code></a>, <a href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sync.html" title="trait core::marker::Sync"><code>Sync</code></a>, and <code>'static</code> bounds.</p>
|
||
<p>This function is same as <a href="fn.spawn.html" title="fn async_task::spawn"><code>spawn()</code></a>, except it does not require <a href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Send.html" title="trait core::marker::Send"><code>Send</code></a>, <a href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sync.html" title="trait core::marker::Sync"><code>Sync</code></a>, and
|
||
<code>'static</code> on <code>future</code> and <code>schedule</code>.</p>
|
||
<h2 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h2>
|
||
<ul>
|
||
<li>If <code>future</code> is not <a href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Send.html" title="trait core::marker::Send"><code>Send</code></a>, its <a href="struct.Runnable.html" title="struct async_task::Runnable"><code>Runnable</code></a> must be used and dropped on the original
|
||
thread.</li>
|
||
<li>If <code>future</code> is not <code>'static</code>, borrowed variables must outlive its <a href="struct.Runnable.html" title="struct async_task::Runnable"><code>Runnable</code></a>.</li>
|
||
<li>If <code>schedule</code> is not <a href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Send.html" title="trait core::marker::Send"><code>Send</code></a> and <a href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sync.html" title="trait core::marker::Sync"><code>Sync</code></a>, all instances of the <a href="struct.Runnable.html" title="struct async_task::Runnable"><code>Runnable</code></a>’s <a href="https://doc.rust-lang.org/1.84.0/core/task/wake/struct.Waker.html" title="struct core::task::wake::Waker"><code>Waker</code></a>
|
||
must be used and dropped on the original thread.</li>
|
||
<li>If <code>schedule</code> is not <code>'static</code>, borrowed variables must outlive all instances of the
|
||
<a href="struct.Runnable.html" title="struct async_task::Runnable"><code>Runnable</code></a>’s <a href="https://doc.rust-lang.org/1.84.0/core/task/wake/struct.Waker.html" title="struct core::task::wake::Waker"><code>Waker</code></a>.</li>
|
||
</ul>
|
||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// The future inside the task.
|
||
</span><span class="kw">let </span>future = <span class="kw">async </span>{
|
||
<span class="macro">println!</span>(<span class="string">"Hello, world!"</span>);
|
||
};
|
||
|
||
<span class="comment">// If the task gets woken up, it will be sent into this channel.
|
||
</span><span class="kw">let </span>(s, r) = flume::unbounded();
|
||
<span class="kw">let </span>schedule = <span class="kw">move </span>|runnable| s.send(runnable).unwrap();
|
||
|
||
<span class="comment">// Create a task with the future and the schedule function.
|
||
</span><span class="kw">let </span>(runnable, task) = <span class="kw">unsafe </span>{ async_task::spawn_unchecked(future, schedule) };</code></pre></div>
|
||
</div></details></section></div></main></body></html> |