232 lines
64 KiB
HTML
232 lines
64 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="Used to create a new `ThreadPool` or to configure the global rayon thread pool."><title>ThreadPoolBuilder in rayon - 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="rayon" 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 struct"><!--[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="#">ThreadPoolBuilder</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../rayon/index.html">rayon</a><span class="version">1.11.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Thread<wbr>Pool<wbr>Builder</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#creating-a-threadpool" title="Creating a ThreadPool">Creating a ThreadPool</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.breadth_first" title="breadth_first">breadth_first</a></li><li><a href="#method.build" title="build">build</a></li><li><a href="#method.build_global" title="build_global">build_global</a></li><li><a href="#method.build_scoped" title="build_scoped">build_scoped</a></li><li><a href="#method.exit_handler" title="exit_handler">exit_handler</a></li><li><a href="#method.new" title="new">new</a></li><li><a href="#method.num_threads" title="num_threads">num_threads</a></li><li><a href="#method.panic_handler" title="panic_handler">panic_handler</a></li><li><a href="#method.spawn_handler" title="spawn_handler">spawn_handler</a></li><li><a href="#method.stack_size" title="stack_size">stack_size</a></li><li><a href="#method.start_handler" title="start_handler">start_handler</a></li><li><a href="#method.thread_name" title="thread_name">thread_name</a></li><li><a href="#method.use_current_thread" title="use_current_thread">use_current_thread</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Debug-for-ThreadPoolBuilder%3CS%3E" title="Debug">Debug</a></li><li><a href="#impl-Default-for-ThreadPoolBuilder" title="Default">Default</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-RefUnwindSafe-for-ThreadPoolBuilder%3CS%3E" title="!RefUnwindSafe">!RefUnwindSafe</a></li><li><a href="#impl-Send-for-ThreadPoolBuilder%3CS%3E" title="!Send">!Send</a></li><li><a href="#impl-Sync-for-ThreadPoolBuilder%3CS%3E" title="!Sync">!Sync</a></li><li><a href="#impl-UnwindSafe-for-ThreadPoolBuilder%3CS%3E" title="!UnwindSafe">!UnwindSafe</a></li><li><a href="#impl-Freeze-for-ThreadPoolBuilder%3CS%3E" title="Freeze">Freeze</a></li><li><a href="#impl-Unpin-for-ThreadPoolBuilder%3CS%3E" title="Unpin">Unpin</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow<T>">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut<T>">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-T" title="From<T>">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into<U>">Into<U></a></li><li><a href="#impl-IntoEither-for-T" title="IntoEither">IntoEither</a></li><li><a href="#impl-Pointable-for-T" title="Pointable">Pointable</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom<U>">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto<U>">TryInto<U></a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate rayon</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">rayon</a></div><h1>Struct <span class="struct">Thread<wbr>Pool<wbr>Builder</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/rayon_core/lib.rs.html#170">Source</a> </span></div><pre class="rust item-decl"><code>pub struct ThreadPoolBuilder<S = DefaultSpawn> { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Used to create a new <a href="struct.ThreadPool.html" title="struct rayon::ThreadPool"><code>ThreadPool</code></a> or to configure the global rayon thread pool.</p>
|
||
<h3 id="creating-a-threadpool"><a class="doc-anchor" href="#creating-a-threadpool">§</a>Creating a ThreadPool</h3>
|
||
<p>The following creates a thread pool with 22 threads.</p>
|
||
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested on wasm">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">let </span>pool = rayon::ThreadPoolBuilder::new().num_threads(<span class="number">22</span>).build().unwrap();</code></pre></div>
|
||
<p>To instead configure the global thread pool, use <a href="struct.ThreadPoolBuilder.html#method.build_global" title="method rayon::ThreadPoolBuilder::build_global"><code>build_global()</code></a>:</p>
|
||
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested on wasm">ⓘ</a><pre class="rust rust-example-rendered"><code>rayon::ThreadPoolBuilder::new().num_threads(<span class="number">22</span>).build_global().unwrap();</code></pre></div></div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-ThreadPoolBuilder" class="impl"><a class="src rightside" href="../src/rayon_core/lib.rs.html#242">Source</a><a href="#impl-ThreadPoolBuilder" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#244">Source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a></h4></section></summary><div class="docblock"><p>Creates and returns a valid rayon thread pool builder, but does not initialize it.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-ThreadPoolBuilder%3CS%3E" class="impl"><a class="src rightside" href="../src/rayon_core/lib.rs.html#251-253">Source</a><a href="#impl-ThreadPoolBuilder%3CS%3E" class="anchor">§</a><h3 class="code-header">impl<S> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><div class="where">where
|
||
S: ThreadSpawn,</div></h3><div class="docblock"><p>Note: the <code>S: ThreadSpawn</code> constraint is an internal implementation detail for the
|
||
default spawn and those set by <a href="#method.spawn_handler"><code>spawn_handler</code></a>.</p>
|
||
</div></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.build" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#256">Source</a><h4 class="code-header">pub fn <a href="#method.build" class="fn">build</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a>, <a class="struct" href="struct.ThreadPoolBuildError.html" title="struct rayon::ThreadPoolBuildError">ThreadPoolBuildError</a>></h4></section></summary><div class="docblock"><p>Creates a new <code>ThreadPool</code> initialized using this configuration.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.build_global" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#277">Source</a><h4 class="code-header">pub fn <a href="#method.build_global" class="fn">build_global</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>, <a class="struct" href="struct.ThreadPoolBuildError.html" title="struct rayon::ThreadPoolBuildError">ThreadPoolBuildError</a>></h4></section></summary><div class="docblock"><p>Initializes the global thread pool. This initialization is
|
||
<strong>optional</strong>. If you do not call this function, the thread pool
|
||
will be automatically initialized with the default
|
||
configuration. Calling <code>build_global</code> is not recommended, except
|
||
in two scenarios:</p>
|
||
<ul>
|
||
<li>You wish to change the default configuration.</li>
|
||
<li>You are running a benchmark, in which case initializing may
|
||
yield slightly more consistent results, since the worker threads
|
||
will already be ready to go even in the first iteration. But
|
||
this cost is minimal.</li>
|
||
</ul>
|
||
<p>Initialization of the global thread pool happens exactly
|
||
once. Once started, the configuration cannot be
|
||
changed. Therefore, if you call <code>build_global</code> a second time, it
|
||
will return an error. An <code>Ok</code> result indicates that this
|
||
is the first initialization of the thread pool.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-ThreadPoolBuilder-1" class="impl"><a class="src rightside" href="../src/rayon_core/lib.rs.html#284">Source</a><a href="#impl-ThreadPoolBuilder-1" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.build_scoped" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#322-325">Source</a><h4 class="code-header">pub fn <a href="#method.build_scoped" class="fn">build_scoped</a><W, F, R>(
|
||
self,
|
||
wrapper: W,
|
||
with_pool: F,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><R, <a class="struct" href="struct.ThreadPoolBuildError.html" title="struct rayon::ThreadPoolBuildError">ThreadPoolBuildError</a>><div class="where">where
|
||
W: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="struct" href="struct.ThreadBuilder.html" title="struct rayon::ThreadBuilder">ThreadBuilder</a>) + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>,
|
||
F: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&<a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a>) -> R,</div></h4></section></summary><div class="docblock"><p>Creates a scoped <code>ThreadPool</code> initialized using this configuration.</p>
|
||
<p>This is a convenience function for building a pool using <a href="https://doc.rust-lang.org/1.93.1/std/thread/scoped/fn.scope.html" title="fn std::thread::scoped::scope"><code>std::thread::scope</code></a>
|
||
to spawn threads in a <a href="struct.ThreadPoolBuilder.html#method.spawn_handler" title="method rayon::ThreadPoolBuilder::spawn_handler"><code>spawn_handler</code></a>.
|
||
The threads in this pool will start by calling <code>wrapper</code>, which should
|
||
do initialization and continue by calling <code>ThreadBuilder::run()</code>.</p>
|
||
<h5 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h5>
|
||
<p>A scoped pool may be useful in combination with scoped thread-local variables.</p>
|
||
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested on wasm">ⓘ</a><pre class="rust rust-example-rendered"><code>
|
||
<span class="macro">scoped_tls::scoped_thread_local!</span>(<span class="kw">static </span>POOL_DATA: Vec<i32>);
|
||
|
||
<span class="kw">fn </span>main() -> <span class="prelude-ty">Result</span><(), rayon::ThreadPoolBuildError> {
|
||
<span class="kw">let </span>pool_data = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
|
||
<span class="comment">// We haven't assigned any TLS data yet.
|
||
</span><span class="macro">assert!</span>(!POOL_DATA.is_set());
|
||
|
||
rayon::ThreadPoolBuilder::new()
|
||
.build_scoped(
|
||
<span class="comment">// Borrow `pool_data` in TLS for each thread.
|
||
</span>|thread| POOL_DATA.set(<span class="kw-2">&</span>pool_data, || thread.run()),
|
||
<span class="comment">// Do some work that needs the TLS data.
|
||
</span>|pool| pool.install(|| <span class="macro">assert!</span>(POOL_DATA.is_set())),
|
||
)<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// Once we've returned, `pool_data` is no longer borrowed.
|
||
</span>drop(pool_data);
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-ThreadPoolBuilder%3CS%3E-1" class="impl"><a class="src rightside" href="../src/rayon_core/lib.rs.html#346">Source</a><a href="#impl-ThreadPoolBuilder%3CS%3E-1" class="anchor">§</a><h3 class="code-header">impl<S> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.spawn_handler" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#433-435">Source</a><h4 class="code-header">pub fn <a href="#method.spawn_handler" class="fn">spawn_handler</a><F>(self, spawn: F) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><CustomSpawn<F>><div class="where">where
|
||
F: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="struct" href="struct.ThreadBuilder.html" title="struct rayon::ThreadBuilder">ThreadBuilder</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/1.93.1/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>>,</div></h4></section></summary><div class="docblock"><p>Sets a custom function for spawning threads.</p>
|
||
<p>Note that the threads will not exit until after the pool is dropped. It
|
||
is up to the caller to wait for thread termination if that is important
|
||
for any invariants. For instance, threads created in <a href="https://doc.rust-lang.org/1.93.1/std/thread/scoped/fn.scope.html" title="fn std::thread::scoped::scope"><code>std::thread::scope</code></a>
|
||
will be joined before that scope returns, and this will block indefinitely
|
||
if the pool is leaked. Furthermore, the global thread pool doesn’t terminate
|
||
until the entire process exits!</p>
|
||
<h5 id="examples-1"><a class="doc-anchor" href="#examples-1">§</a>Examples</h5>
|
||
<p>A minimal spawn handler just needs to call <code>run()</code> from an independent thread.</p>
|
||
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested on wasm">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() -> <span class="prelude-ty">Result</span><(), rayon::ThreadPoolBuildError> {
|
||
<span class="kw">let </span>pool = rayon::ThreadPoolBuilder::new()
|
||
.spawn_handler(|thread| {
|
||
std::thread::spawn(|| thread.run());
|
||
<span class="prelude-val">Ok</span>(())
|
||
})
|
||
.build()<span class="question-mark">?</span>;
|
||
|
||
pool.install(|| <span class="macro">println!</span>(<span class="string">"Hello from my custom thread!"</span>));
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div>
|
||
<p>The default spawn handler sets the name and stack size if given, and propagates
|
||
any errors from the thread builder.</p>
|
||
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested on wasm">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() -> <span class="prelude-ty">Result</span><(), rayon::ThreadPoolBuildError> {
|
||
<span class="kw">let </span>pool = rayon::ThreadPoolBuilder::new()
|
||
.spawn_handler(|thread| {
|
||
<span class="kw">let </span><span class="kw-2">mut </span>b = std::thread::Builder::new();
|
||
<span class="kw">if let </span><span class="prelude-val">Some</span>(name) = thread.name() {
|
||
b = b.name(name.to_owned());
|
||
}
|
||
<span class="kw">if let </span><span class="prelude-val">Some</span>(stack_size) = thread.stack_size() {
|
||
b = b.stack_size(stack_size);
|
||
}
|
||
b.spawn(|| thread.run())<span class="question-mark">?</span>;
|
||
<span class="prelude-val">Ok</span>(())
|
||
})
|
||
.build()<span class="question-mark">?</span>;
|
||
|
||
pool.install(|| <span class="macro">println!</span>(<span class="string">"Hello from my fully custom thread!"</span>));
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div>
|
||
<p>This can also be used for a pool of scoped threads like <a href="https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html"><code>crossbeam::scope</code></a>,
|
||
or <a href="https://doc.rust-lang.org/1.93.1/std/thread/scoped/fn.scope.html" title="fn std::thread::scoped::scope"><code>std::thread::scope</code></a> introduced in Rust 1.63, which is encapsulated in
|
||
<a href="struct.ThreadPoolBuilder.html#method.build_scoped" title="method rayon::ThreadPoolBuilder::build_scoped"><code>build_scoped</code></a>.</p>
|
||
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested on wasm">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() -> <span class="prelude-ty">Result</span><(), rayon::ThreadPoolBuildError> {
|
||
std::thread::scope(|scope| {
|
||
<span class="kw">let </span>pool = rayon::ThreadPoolBuilder::new()
|
||
.spawn_handler(|thread| {
|
||
<span class="kw">let </span><span class="kw-2">mut </span>builder = std::thread::Builder::new();
|
||
<span class="kw">if let </span><span class="prelude-val">Some</span>(name) = thread.name() {
|
||
builder = builder.name(name.to_string());
|
||
}
|
||
<span class="kw">if let </span><span class="prelude-val">Some</span>(size) = thread.stack_size() {
|
||
builder = builder.stack_size(size);
|
||
}
|
||
builder.spawn_scoped(scope, || {
|
||
<span class="comment">// Add any scoped initialization here, then run!
|
||
</span>thread.run()
|
||
})<span class="question-mark">?</span>;
|
||
<span class="prelude-val">Ok</span>(())
|
||
})
|
||
.build()<span class="question-mark">?</span>;
|
||
|
||
pool.install(|| <span class="macro">println!</span>(<span class="string">"Hello from my custom scoped thread!"</span>));
|
||
<span class="prelude-val">Ok</span>(())
|
||
})
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.thread_name" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#496-498">Source</a><h4 class="code-header">pub fn <a href="#method.thread_name" class="fn">thread_name</a><F>(self, closure: F) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><div class="where">where
|
||
F: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/string/struct.String.html" title="struct alloc::string::String">String</a> + 'static,</div></h4></section></summary><div class="docblock"><p>Sets a closure which takes a thread index and returns
|
||
the thread’s name.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.num_threads" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#529">Source</a><h4 class="code-header">pub fn <a href="#method.num_threads" class="fn">num_threads</a>(self, num_threads: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h4></section></summary><div class="docblock"><p>Sets the number of threads to be used in the rayon thread pool.</p>
|
||
<p>If you specify a non-zero number of threads using this
|
||
function, then the resulting thread pools are guaranteed to
|
||
start at most this number of threads.</p>
|
||
<p>If <code>num_threads</code> is 0, or you do not call this function, then
|
||
the Rayon runtime will select the number of threads
|
||
automatically. At present, this is based on the
|
||
<code>RAYON_NUM_THREADS</code> environment variable (if set),
|
||
or the number of logical CPUs (otherwise).
|
||
In the future, however, the default behavior may
|
||
change to dynamically add or remove threads as needed.</p>
|
||
<p><strong>Future compatibility warning:</strong> Given the default behavior
|
||
may change in the future, if you wish to rely on a fixed
|
||
number of threads, you should use this function to specify
|
||
that number. To reproduce the current default behavior, you
|
||
may wish to use <a href="https://doc.rust-lang.org/1.93.1/std/thread/functions/fn.available_parallelism.html" title="fn std::thread::functions::available_parallelism"><code>std::thread::available_parallelism</code></a>
|
||
to query the number of CPUs dynamically.</p>
|
||
<p><strong>Old environment variable:</strong> <code>RAYON_NUM_THREADS</code> is a one-to-one
|
||
replacement of the now deprecated <code>RAYON_RS_NUM_CPUS</code> environment
|
||
variable. If both variables are specified, <code>RAYON_NUM_THREADS</code> will
|
||
be preferred.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.use_current_thread" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#547">Source</a><h4 class="code-header">pub fn <a href="#method.use_current_thread" class="fn">use_current_thread</a>(self) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h4></section></summary><div class="docblock"><p>Use the current thread as one of the threads in the pool.</p>
|
||
<p>The current thread is guaranteed to be at index 0, and since the thread is not managed by
|
||
rayon, the spawn and exit handlers do not run for that thread.</p>
|
||
<p>Note that the current thread won’t run the main work-stealing loop, so jobs spawned into
|
||
the thread pool will generally not be picked up automatically by this thread unless you
|
||
yield to rayon in some way, like via <a href="fn.yield_now.html" title="fn rayon::yield_now"><code>yield_now()</code></a>, <a href="fn.yield_local.html" title="fn rayon::yield_local"><code>yield_local()</code></a>, or <a href="fn.scope.html" title="fn rayon::scope"><code>scope()</code></a>.</p>
|
||
<h5 id="local-thread-pools"><a class="doc-anchor" href="#local-thread-pools">§</a>Local thread pools</h5>
|
||
<p>Using this in a local thread pool means the registry will be leaked. In future versions
|
||
there might be a way of cleaning up the current-thread state.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.panic_handler" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#571-573">Source</a><h4 class="code-header">pub fn <a href="#method.panic_handler" class="fn">panic_handler</a><H>(self, panic_handler: H) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><div class="where">where
|
||
H: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/any/trait.Any.html" title="trait core::any::Any">Any</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>>) + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static,</div></h4></section></summary><div class="docblock"><p>Normally, whenever Rayon catches a panic, it tries to
|
||
propagate it to someplace sensible, to try and reflect the
|
||
semantics of sequential execution. But in some cases,
|
||
particularly with the <code>spawn()</code> APIs, there is no
|
||
obvious place where we should propagate the panic to.
|
||
In that case, this panic handler is invoked.</p>
|
||
<p>If no panic handler is set, the default is to abort the
|
||
process, under the principle that panics should not go
|
||
unobserved.</p>
|
||
<p>If the panic handler itself panics, this will abort the
|
||
process. To prevent this, wrap the body of your panic handler
|
||
in a call to <code>std::panic::catch_unwind()</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.stack_size" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#585">Source</a><h4 class="code-header">pub fn <a href="#method.stack_size" class="fn">stack_size</a>(self, stack_size: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h4></section></summary><div class="docblock"><p>Sets the stack size of the worker threads</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.breadth_first" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#618">Source</a><h4 class="code-header">pub fn <a href="#method.breadth_first" class="fn">breadth_first</a>(self) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated: use <code>scope_fifo</code> and <code>spawn_fifo</code> for similar effect</span></div></span></summary><div class="docblock"><p><strong>(DEPRECATED)</strong> Suggest to worker threads that they execute
|
||
spawned jobs in a “breadth-first” fashion.</p>
|
||
<p>Typically, when a worker thread is idle or blocked, it will
|
||
attempt to execute the job from the <em>top</em> of its local deque of
|
||
work (i.e., the job most recently spawned). If this flag is set
|
||
to true, however, workers will prefer to execute in a
|
||
<em>breadth-first</em> fashion – that is, they will search for jobs at
|
||
the <em>bottom</em> of their local deque. (At present, workers <em>always</em>
|
||
steal from the bottom of other workers’ deques, regardless of
|
||
the setting of this flag.)</p>
|
||
<p>If you think of the tasks as a tree, where a parent task
|
||
spawns its children in the tree, then this flag loosely
|
||
corresponds to doing a breadth-first traversal of the tree,
|
||
whereas the default would be to do a depth-first traversal.</p>
|
||
<p><strong>Note that this is an “execution hint”.</strong> Rayon’s task
|
||
execution is highly dynamic and the precise order in which
|
||
independent tasks are executed is not intended to be
|
||
guaranteed.</p>
|
||
<p>This <code>breadth_first()</code> method is now deprecated per <a href="https://github.com/rayon-rs/rfcs/blob/main/accepted/rfc0001-scope-scheduling.md">RFC #1</a>,
|
||
and in the future its effect may be removed. Consider using
|
||
<a href="fn.scope_fifo.html" title="fn rayon::scope_fifo"><code>scope_fifo()</code></a> for a similar effect.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.start_handler" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#638-640">Source</a><h4 class="code-header">pub fn <a href="#method.start_handler" class="fn">start_handler</a><H>(self, start_handler: H) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><div class="where">where
|
||
H: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>) + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static,</div></h4></section></summary><div class="docblock"><p>Sets a callback to be invoked on thread start.</p>
|
||
<p>The closure is passed the index of the thread on which it is invoked.
|
||
Note that this same closure may be invoked multiple times in parallel.
|
||
If this closure panics, the panic will be passed to the panic handler.
|
||
If that handler returns, then startup will continue normally.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.exit_handler" class="method"><a class="src rightside" href="../src/rayon_core/lib.rs.html#657-659">Source</a><h4 class="code-header">pub fn <a href="#method.exit_handler" class="fn">exit_handler</a><H>(self, exit_handler: H) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><div class="where">where
|
||
H: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>) + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static,</div></h4></section></summary><div class="docblock"><p>Sets a callback to be invoked on thread exit.</p>
|
||
<p>The closure is passed the index of the thread on which it is invoked.
|
||
Note that this same closure may be invoked multiple times in parallel.
|
||
If this closure panics, the panic will be passed to the panic handler.
|
||
If that handler returns, then the thread will exit normally.</p>
|
||
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-ThreadPoolBuilder%3CS%3E" class="impl"><a class="src rightside" href="../src/rayon_core/lib.rs.html#791">Source</a><a href="#impl-Debug-for-ThreadPoolBuilder%3CS%3E" class="anchor">§</a><h3 class="code-header">impl<S> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../src/rayon_core/lib.rs.html#792">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.93.1/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/1.93.1/core/fmt/struct.Error.html" title="struct core::fmt::Error">Error</a>></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.93.1/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Default-for-ThreadPoolBuilder" class="impl"><a class="src rightside" href="../src/rayon_core/lib.rs.html#226">Source</a><a href="#impl-Default-for-ThreadPoolBuilder" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.default" class="method trait-impl"><a class="src rightside" href="../src/rayon_core/lib.rs.html#227">Source</a><a href="#method.default" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/default/trait.Default.html#tymethod.default" class="fn">default</a>() -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a></h4></section></summary><div class='docblock'>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/1.93.1/core/default/trait.Default.html#tymethod.default">Read more</a></div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-ThreadPoolBuilder%3CS%3E" class="impl"><a href="#impl-Freeze-for-ThreadPoolBuilder%3CS%3E" class="anchor">§</a><h3 class="code-header">impl<S> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><div class="where">where
|
||
S: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a>,</div></h3></section><section id="impl-RefUnwindSafe-for-ThreadPoolBuilder%3CS%3E" class="impl"><a href="#impl-RefUnwindSafe-for-ThreadPoolBuilder%3CS%3E" class="anchor">§</a><h3 class="code-header">impl<S = DefaultSpawn> !<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h3></section><section id="impl-Send-for-ThreadPoolBuilder%3CS%3E" class="impl"><a href="#impl-Send-for-ThreadPoolBuilder%3CS%3E" class="anchor">§</a><h3 class="code-header">impl<S = DefaultSpawn> !<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h3></section><section id="impl-Sync-for-ThreadPoolBuilder%3CS%3E" class="impl"><a href="#impl-Sync-for-ThreadPoolBuilder%3CS%3E" class="anchor">§</a><h3 class="code-header">impl<S = DefaultSpawn> !<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h3></section><section id="impl-Unpin-for-ThreadPoolBuilder%3CS%3E" class="impl"><a href="#impl-Unpin-for-ThreadPoolBuilder%3CS%3E" class="anchor">§</a><h3 class="code-header">impl<S> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><div class="where">where
|
||
S: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></h3></section><section id="impl-UnwindSafe-for-ThreadPoolBuilder%3CS%3E" class="impl"><a href="#impl-UnwindSafe-for-ThreadPoolBuilder%3CS%3E" class="anchor">§</a><h3 class="code-header">impl<S = DefaultSpawn> !<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/any.rs.html#138">Source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
||
T: 'static + ?<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></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/any.rs.html#139">Source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.93.1/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/1.93.1/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#212">Source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
||
T: ?<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></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#214">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#221">Source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
||
T: ?<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></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#222">Source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#785">Source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#788">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#767-769">Source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#777">Source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.Into.html#tymethod.into" class="fn">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/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-IntoEither-for-T" class="impl"><a class="src rightside" href="../src/either/into_either.rs.html#64">Source</a><a href="#impl-IntoEither-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="../either/into_either/trait.IntoEither.html" title="trait either::into_either::IntoEither">IntoEither</a> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into_either" class="method trait-impl"><a class="src rightside" href="../src/either/into_either.rs.html#29">Source</a><a href="#method.into_either" class="anchor">§</a><h4 class="code-header">fn <a href="../either/into_either/trait.IntoEither.html#method.into_either" class="fn">into_either</a>(self, into_left: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a>) -> <a class="enum" href="iter/enum.Either.html" title="enum rayon::iter::Either">Either</a><Self, Self> <a href="#" class="tooltip" data-notable-ty="Either<Self, Self>">ⓘ</a></h4></section></summary><div class='docblock'>Converts <code>self</code> into a <a href="iter/enum.Either.html#variant.Left" title="variant rayon::iter::Either::Left"><code>Left</code></a> variant of <a href="iter/enum.Either.html" title="enum rayon::iter::Either"><code>Either<Self, Self></code></a>
|
||
if <code>into_left</code> is <code>true</code>.
|
||
Converts <code>self</code> into a <a href="iter/enum.Either.html#variant.Right" title="variant rayon::iter::Either::Right"><code>Right</code></a> variant of <a href="iter/enum.Either.html" title="enum rayon::iter::Either"><code>Either<Self, Self></code></a>
|
||
otherwise. <a href="../either/into_either/trait.IntoEither.html#method.into_either">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.into_either_with" class="method trait-impl"><a class="src rightside" href="../src/either/into_either.rs.html#55-57">Source</a><a href="#method.into_either_with" class="anchor">§</a><h4 class="code-header">fn <a href="../either/into_either/trait.IntoEither.html#method.into_either_with" class="fn">into_either_with</a><F>(self, into_left: F) -> <a class="enum" href="iter/enum.Either.html" title="enum rayon::iter::Either">Either</a><Self, Self> <a href="#" class="tooltip" data-notable-ty="Either<Self, Self>">ⓘ</a><div class="where">where
|
||
F: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&Self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class='docblock'>Converts <code>self</code> into a <a href="iter/enum.Either.html#variant.Left" title="variant rayon::iter::Either::Left"><code>Left</code></a> variant of <a href="iter/enum.Either.html" title="enum rayon::iter::Either"><code>Either<Self, Self></code></a>
|
||
if <code>into_left(&self)</code> returns <code>true</code>.
|
||
Converts <code>self</code> into a <a href="iter/enum.Either.html#variant.Right" title="variant rayon::iter::Either::Right"><code>Right</code></a> variant of <a href="iter/enum.Either.html" title="enum rayon::iter::Either"><code>Either<Self, Self></code></a>
|
||
otherwise. <a href="../either/into_either/trait.IntoEither.html#method.into_either_with">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Pointable-for-T" class="impl"><a class="src rightside" href="../src/crossbeam_epoch/atomic.rs.html#194">Source</a><a href="#impl-Pointable-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="../crossbeam_epoch/atomic/trait.Pointable.html" title="trait crossbeam_epoch::atomic::Pointable">Pointable</a> for T</h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedconstant.ALIGN" class="associatedconstant trait-impl"><a class="src rightside" href="../src/crossbeam_epoch/atomic.rs.html#195">Source</a><a href="#associatedconstant.ALIGN" class="anchor">§</a><h4 class="code-header">const <a href="../crossbeam_epoch/atomic/trait.Pointable.html#associatedconstant.ALIGN" class="constant">ALIGN</a>: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a></h4></section></summary><div class='docblock'>The alignment of pointer.</div></details><details class="toggle" open><summary><section id="associatedtype.Init" class="associatedtype trait-impl"><a class="src rightside" href="../src/crossbeam_epoch/atomic.rs.html#197">Source</a><a href="#associatedtype.Init" class="anchor">§</a><h4 class="code-header">type <a href="../crossbeam_epoch/atomic/trait.Pointable.html#associatedtype.Init" class="associatedtype">Init</a> = T</h4></section></summary><div class='docblock'>The type for initializers.</div></details><details class="toggle method-toggle" open><summary><section id="method.init" class="method trait-impl"><a class="src rightside" href="../src/crossbeam_epoch/atomic.rs.html#199">Source</a><a href="#method.init" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.init" class="fn">init</a>(init: <T as <a class="trait" href="../crossbeam_epoch/atomic/trait.Pointable.html" title="trait crossbeam_epoch::atomic::Pointable">Pointable</a>>::<a class="associatedtype" href="../crossbeam_epoch/atomic/trait.Pointable.html#associatedtype.Init" title="type crossbeam_epoch::atomic::Pointable::Init">Init</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a></h4></section></summary><div class='docblock'>Initializes a with the given initializer. <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.init">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.deref" class="method trait-impl"><a class="src rightside" href="../src/crossbeam_epoch/atomic.rs.html#203">Source</a><a href="#method.deref" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.deref" class="fn">deref</a><'a>(ptr: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&'a T</a></h4></section></summary><div class='docblock'>Dereferences the given pointer. <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.deref">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.deref_mut" class="method trait-impl"><a class="src rightside" href="../src/crossbeam_epoch/atomic.rs.html#207">Source</a><a href="#method.deref_mut" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.deref_mut" class="fn">deref_mut</a><'a>(ptr: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&'a mut T</a></h4></section></summary><div class='docblock'>Mutably dereferences the given pointer. <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.deref_mut">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.drop" class="method trait-impl"><a class="src rightside" href="../src/crossbeam_epoch/atomic.rs.html#211">Source</a><a href="#method.drop" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.drop" class="fn">drop</a>(ptr: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>)</h4></section></summary><div class='docblock'>Drops the object pointed to by the given pointer. <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.drop">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#827-829">Source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#831">Source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.93.1/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="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#834">Source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/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="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#811-813">Source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#815">Source</a><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/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="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#818">Source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/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><script type="text/json" id="notable-traits-data">{"Either<Self, Self>":"<h3>Notable traits for <code><a class=\"enum\" href=\"iter/enum.Either.html\" title=\"enum rayon::iter::Either\">Either</a><L, R></code></h3><pre><code><div class=\"where\">impl<L, R> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"enum\" href=\"iter/enum.Either.html\" title=\"enum rayon::iter::Either\">Either</a><L, R><div class=\"where\">where\n L: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a>,\n R: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a><Item = <L as <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a>>::<a class=\"associatedtype\" href=\"https://doc.rust-lang.org/1.93.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" title=\"type core::iter::traits::iterator::Iterator::Item\">Item</a>>,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.93.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = <L as <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a>>::<a class=\"associatedtype\" href=\"https://doc.rust-lang.org/1.93.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" title=\"type core::iter::traits::iterator::Iterator::Item\">Item</a>;</div><div class=\"where\">impl<L, R> <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> for <a class=\"enum\" href=\"iter/enum.Either.html\" title=\"enum rayon::iter::Either\">Either</a><L, R><div class=\"where\">where\n L: <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>,\n R: <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><Output = <L as <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>>::<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>>,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.93.1/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</a> = <L as <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>>::<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>;</div><div class=\"where\">impl<L, R> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/std/io/trait.Read.html\" title=\"trait std::io::Read\">Read</a> for <a class=\"enum\" href=\"iter/enum.Either.html\" title=\"enum rayon::iter::Either\">Either</a><L, R><div class=\"where\">where\n L: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/std/io/trait.Read.html\" title=\"trait std::io::Read\">Read</a>,\n R: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/std/io/trait.Read.html\" title=\"trait std::io::Read\">Read</a>,</div></div><div class=\"where\">impl<L, R> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/std/io/trait.Write.html\" title=\"trait std::io::Write\">Write</a> for <a class=\"enum\" href=\"iter/enum.Either.html\" title=\"enum rayon::iter::Either\">Either</a><L, R><div class=\"where\">where\n L: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/std/io/trait.Write.html\" title=\"trait std::io::Write\">Write</a>,\n R: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/std/io/trait.Write.html\" title=\"trait std::io::Write\">Write</a>,</div></div>"}</script></section></div></main></body></html> |