45 lines
9.6 KiB
HTML
45 lines
9.6 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="Traits and functions used to implement parallel iteration. These are low-level details – users of parallel iterators should not need to interact with them directly. See the `plumbing` README for a general overview."><title>rayon::iter::plumbing - 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 mod"><!--[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="#">Module plumbing</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="#">Module plumbing</a></h2><h3><a href="#traits">Module Items</a></h3><ul class="block"><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></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>Module <span>plumbing</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/iter/plumbing/mod.rs.html#1-476">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Traits and functions used to implement parallel iteration. These are
|
||
low-level details – users of parallel iterators should not need to
|
||
interact with them directly. See <a href="https://github.com/rayon-rs/rayon/blob/main/src/iter/plumbing/README.md">the <code>plumbing</code> README</a> for a general overview.</p>
|
||
</div></details><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.Consumer.html" title="trait rayon::iter::plumbing::Consumer">Consumer</a></dt><dd>A consumer is effectively a <a href="https://doc.rust-lang.org/1.93.1/core/iter/traits/iterator/trait.Iterator.html#method.fold" title="method core::iter::traits::iterator::Iterator::fold">generalized “fold” operation</a>,
|
||
and in fact each consumer will eventually be converted into a
|
||
<a href="trait.Folder.html" title="trait rayon::iter::plumbing::Folder"><code>Folder</code></a>. What makes a consumer special is that, like a
|
||
<a href="trait.Producer.html" title="trait rayon::iter::plumbing::Producer"><code>Producer</code></a>, it can be <strong>split</strong> into multiple consumers using
|
||
the <code>split_at</code> method. When a consumer is split, it produces two
|
||
consumers, as well as a <strong>reducer</strong>. The two consumers can be fed
|
||
items independently, and when they are done the reducer is used to
|
||
combine their two results into one. See <a href="https://github.com/rayon-rs/rayon/blob/main/src/iter/plumbing/README.md">the <code>plumbing</code>
|
||
README</a> for further details.</dd><dt><a class="trait" href="trait.Folder.html" title="trait rayon::iter::plumbing::Folder">Folder</a></dt><dd>The <code>Folder</code> trait encapsulates <a href="https://doc.rust-lang.org/1.93.1/core/iter/traits/iterator/trait.Iterator.html#method.fold" title="method core::iter::traits::iterator::Iterator::fold">the standard fold
|
||
operation</a>. It can be fed many items using the <code>consume</code>
|
||
method. At the end, once all items have been consumed, it can then
|
||
be converted (using <code>complete</code>) into a final value.</dd><dt><a class="trait" href="trait.Producer.html" title="trait rayon::iter::plumbing::Producer">Producer</a></dt><dd>A <code>Producer</code> is effectively a “splittable <code>IntoIterator</code>”. That
|
||
is, a producer is a value which can be converted into an iterator
|
||
at any time: at that point, it simply produces items on demand,
|
||
like any iterator. But what makes a <code>Producer</code> special is that,
|
||
<em>before</em> we convert to an iterator, we can also <strong>split</strong> it at a
|
||
particular point using the <code>split_at</code> method. This will yield up
|
||
two producers, one producing the items before that point, and one
|
||
producing the items after that point (these two producers can then
|
||
independently be split further, or be converted into iterators).
|
||
In Rayon, this splitting is used to divide between threads.
|
||
See <a href="https://github.com/rayon-rs/rayon/blob/main/src/iter/plumbing/README.md">the <code>plumbing</code> README</a> for further details.</dd><dt><a class="trait" href="trait.ProducerCallback.html" title="trait rayon::iter::plumbing::ProducerCallback">Producer<wbr>Callback</a></dt><dd>The <code>ProducerCallback</code> trait is a kind of generic closure,
|
||
<a href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">analogous to <code>FnOnce</code></a>. See <a href="https://github.com/rayon-rs/rayon/blob/main/src/iter/plumbing/README.md#producer-callback">the corresponding section in
|
||
the plumbing README</a> for more details.</dd><dt><a class="trait" href="trait.Reducer.html" title="trait rayon::iter::plumbing::Reducer">Reducer</a></dt><dd>The reducer is the final step of a <code>Consumer</code> – after a consumer
|
||
has been split into two parts, and each of those parts has been
|
||
fully processed, we are left with two results. The reducer is then
|
||
used to combine those two results into one. See <a href="https://github.com/rayon-rs/rayon/blob/main/src/iter/plumbing/README.md">the <code>plumbing</code>
|
||
README</a> for further details.</dd><dt><a class="trait" href="trait.UnindexedConsumer.html" title="trait rayon::iter::plumbing::UnindexedConsumer">Unindexed<wbr>Consumer</a></dt><dd>A stateless consumer can be freely copied. These consumers can be
|
||
used like regular consumers, but they also support a
|
||
<code>split_off_left</code> method that does not take an index to split, but
|
||
simply splits at some arbitrary point (<code>for_each</code>, for example,
|
||
produces an unindexed consumer).</dd><dt><a class="trait" href="trait.UnindexedProducer.html" title="trait rayon::iter::plumbing::UnindexedProducer">Unindexed<wbr>Producer</a></dt><dd>A variant on <code>Producer</code> which does not know its exact length or
|
||
cannot represent it in a <code>usize</code>. These producers act like
|
||
ordinary producers except that they cannot be told to split at a
|
||
particular point. Instead, you just ask them to split ‘somewhere’.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.bridge.html" title="fn rayon::iter::plumbing::bridge">bridge</a></dt><dd>This helper function is used to “connect” a parallel iterator to a
|
||
consumer. It will convert the <code>par_iter</code> into a producer P and
|
||
then pull items from P and feed them to <code>consumer</code>, splitting and
|
||
creating parallel threads as needed.</dd><dt><a class="fn" href="fn.bridge_producer_consumer.html" title="fn rayon::iter::plumbing::bridge_producer_consumer">bridge_<wbr>producer_<wbr>consumer</a></dt><dd>This helper function is used to “connect” a producer and a
|
||
consumer. You may prefer to call <a href="fn.bridge.html" title="fn rayon::iter::plumbing::bridge"><code>bridge()</code></a>, which wraps this
|
||
function. This function will draw items from <code>producer</code> and feed
|
||
them to <code>consumer</code>, splitting and creating parallel tasks when
|
||
needed.</dd><dt><a class="fn" href="fn.bridge_unindexed.html" title="fn rayon::iter::plumbing::bridge_unindexed">bridge_<wbr>unindexed</a></dt><dd>A variant of <a href="fn.bridge_producer_consumer.html" title="fn rayon::iter::plumbing::bridge_producer_consumer"><code>bridge_producer_consumer()</code></a> where the producer is an unindexed producer.</dd></dl></section></div></main></body></html> |