Files
GopherGate/target/doc/rayon/iter/trait.ParallelBridge.html
2026-02-26 12:00:21 -05:00

38 lines
8.1 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="Conversion trait to convert an `Iterator` to a `ParallelIterator`."><title>ParallelBridge in rayon::iter - 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 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="#">ParallelBridge</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="#">Parallel<wbr>Bridge</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.par_bridge" title="par_bridge">par_bridge</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 rayon::<wbr>iter</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>::<wbr><a href="index.html">iter</a></div><h1>Trait <span class="trait">Parallel<wbr>Bridge</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/rayon/iter/par_bridge.rs.html#53-56">Source</a> </span></div><pre class="rust item-decl"><code>pub trait ParallelBridge: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
// Required method
fn <a href="#tymethod.par_bridge" class="fn">par_bridge</a>(self) -&gt; <a class="struct" href="struct.IterBridge.html" title="struct rayon::iter::IterBridge">IterBridge</a>&lt;Self&gt;;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Conversion trait to convert an <code>Iterator</code> to a <code>ParallelIterator</code>.</p>
<p>This creates a “bridge” from a sequential iterator to a parallel one, by distributing its items
across the Rayon thread pool. This has the advantage of being able to parallelize just about
anything, but the resulting <code>ParallelIterator</code> can be less efficient than if you started with
<code>par_iter</code> instead. However, it can still be useful for iterators that are difficult to
parallelize by other means, like channels or file or network I/O.</p>
<p>Iterator items are pulled by <code>next()</code> one at a time, synchronized from each thread that is
ready for work, so this may become a bottleneck if the serial iterator cant keep up with the
parallel demand. The items are not buffered by <code>IterBridge</code>, so its fine to use this with
large or even unbounded iterators.</p>
<p>The resulting iterator is not guaranteed to keep the order of the original iterator.</p>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<p>To use this trait, take an existing <code>Iterator</code> and call <code>par_bridge</code> on it. After that, you can
use any of the <code>ParallelIterator</code> methods:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rayon::iter::ParallelBridge;
<span class="kw">use </span>rayon::prelude::ParallelIterator;
<span class="kw">use </span>std::sync::mpsc::channel;
<span class="kw">let </span>rx = {
<span class="kw">let </span>(tx, rx) = channel();
tx.send(<span class="string">"one!"</span>);
tx.send(<span class="string">"two!"</span>);
tx.send(<span class="string">"three!"</span>);
rx
};
<span class="kw">let </span><span class="kw-2">mut </span>output: Vec&lt;<span class="kw-2">&amp;</span><span class="lifetime">'static </span>str&gt; = rx.into_iter().par_bridge().collect();
output.sort_unstable();
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;*</span>output, <span class="kw-2">&amp;</span>[<span class="string">"one!"</span>, <span class="string">"three!"</span>, <span class="string">"two!"</span>]);</code></pre></div></div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.par_bridge" class="method"><a class="src rightside" href="../../src/rayon/iter/par_bridge.rs.html#55">Source</a><h4 class="code-header">fn <a href="#tymethod.par_bridge" class="fn">par_bridge</a>(self) -&gt; <a class="struct" href="struct.IterBridge.html" title="struct rayon::iter::IterBridge">IterBridge</a>&lt;Self&gt;</h4></section></summary><div class="docblock"><p>Creates a bridge from this type to a <code>ParallelIterator</code>.</p>
</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-ParallelBridge-for-T" class="impl"><a class="src rightside" href="../../src/rayon/iter/par_bridge.rs.html#58-65">Source</a><a href="#impl-ParallelBridge-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="trait.ParallelBridge.html" title="trait rayon::iter::ParallelBridge">ParallelBridge</a> for T<div class="where">where
T: <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>&lt;Item: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,</div></h3></section></div><script src="../../trait.impl/rayon/iter/par_bridge/trait.ParallelBridge.js" async></script></section></div></main></body></html>