blob: 5c5219549dd799f92cbb29d2c324ad722f96bcce [file] [log] [blame]
<!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="A `Producer` is effectively a “splittable `IntoIterator`”. 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 `Producer` special is that, before we convert to an iterator, we can also split it at a particular point using the `split_at` 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 the `plumbing` README for further details."><meta name="keywords" content="rust, rustlang, rust-lang, Producer"><title>Producer in rayon::iter::plumbing - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../normalize.css"><link rel="stylesheet" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../ayu.css" disabled><link rel="stylesheet" href="../../../dark.css" disabled><link rel="stylesheet" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.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><a class="sidebar-logo" href="../../../rayon/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../rayon/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Producer</a></h2><div class="sidebar-elems"><section><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.IntoIter">IntoIter</a></li><li><a href="#associatedtype.Item">Item</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.into_iter">into_iter</a></li><li><a href="#tymethod.split_at">split_at</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.fold_with">fold_with</a></li><li><a href="#method.max_len">max_len</a></li><li><a href="#method.min_len">min_len</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In rayon::iter::plumbing</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Trait <a href="../../index.html">rayon</a>::<wbr><a href="../index.html">iter</a>::<wbr><a href="index.html">plumbing</a>::<wbr><a class="trait" href="#">Producer</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../../src/rayon/iter/plumbing/mod.rs.html#59-112">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust trait"><code>pub trait Producer: Send + Sized {
type <a href="#associatedtype.Item" class="associatedtype">Item</a>;
type <a href="#associatedtype.IntoIter" class="associatedtype">IntoIter</a>: Iterator&lt;Item = Self::<a class="associatedtype" href="trait.Producer.html#associatedtype.Item" title="type rayon::iter::plumbing::Producer::Item">Item</a>&gt; + DoubleEndedIterator + ExactSizeIterator;
fn <a href="#tymethod.into_iter" class="fnname">into_iter</a>(self) -&gt; Self::<a class="associatedtype" href="trait.Producer.html#associatedtype.IntoIter" title="type rayon::iter::plumbing::Producer::IntoIter">IntoIter</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.split_at" class="fnname">split_at</a>(self, index: usize) -&gt; (Self, Self);
fn <a href="#method.min_len" class="fnname">min_len</a>(&amp;self) -&gt; usize { ... }
<span class="item-spacer"></span> fn <a href="#method.max_len" class="fnname">max_len</a>(&amp;self) -&gt; usize { ... }
<span class="item-spacer"></span> fn <a href="#method.fold_with" class="fnname">fold_with</a>&lt;F&gt;(self, folder: F) -&gt; F<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="trait.Folder.html" title="trait rayon::iter::plumbing::Folder">Folder</a>&lt;Self::<a class="associatedtype" href="trait.Producer.html#associatedtype.Item" title="type rayon::iter::plumbing::Producer::Item">Item</a>&gt;</span>,
{ ... }
}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>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/master/src/iter/plumbing/README.md">the <code>plumbing</code> README</a> for further details.</p>
<p>Note that each producer will always produce a fixed number of
items N. However, this number N is not queryable through the API;
the consumer is expected to track it.</p>
<p>NB. You might expect <code>Producer</code> to extend the <code>IntoIterator</code>
trait. However, <a href="https://github.com/rust-lang/rust/issues/20671">rust-lang/rust#20671</a> prevents us from
declaring the DoubleEndedIterator and ExactSizeIterator
constraints on a required IntoIterator trait, so we inline
IntoIterator here until that issue is fixed.</p>
</div></details><h2 id="required-associated-types" class="small-section-header">Required Associated Types<a href="#required-associated-types" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="associatedtype.Item" class="method has-srclink"><a class="srclink rightside" href="../../../src/rayon/iter/plumbing/mod.rs.html#62">source</a><h4 class="code-header">type <a href="#associatedtype.Item" class="associatedtype">Item</a></h4></section></summary><div class="docblock"><p>The type of item that will be produced by this producer once
it is converted into an iterator.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="associatedtype.IntoIter" class="method has-srclink"><a class="srclink rightside" href="../../../src/rayon/iter/plumbing/mod.rs.html#65">source</a><h4 class="code-header">type <a href="#associatedtype.IntoIter" class="associatedtype">IntoIter</a>: Iterator&lt;Item = Self::<a class="associatedtype" href="trait.Producer.html#associatedtype.Item" title="type rayon::iter::plumbing::Producer::Item">Item</a>&gt; + DoubleEndedIterator + ExactSizeIterator</h4></section></summary><div class="docblock"><p>The type of iterator we will become.</p>
</div></details></div><h2 id="required-methods" class="small-section-header">Required Methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.into_iter" class="method has-srclink"><a class="srclink rightside" href="../../../src/rayon/iter/plumbing/mod.rs.html#69">source</a><h4 class="code-header">fn <a href="#tymethod.into_iter" class="fnname">into_iter</a>(self) -&gt; Self::<a class="associatedtype" href="trait.Producer.html#associatedtype.IntoIter" title="type rayon::iter::plumbing::Producer::IntoIter">IntoIter</a></h4></section></summary><div class="docblock"><p>Convert <code>self</code> into an iterator; at this point, no more parallel splits
are possible.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.split_at" class="method has-srclink"><a class="srclink rightside" href="../../../src/rayon/iter/plumbing/mod.rs.html#100">source</a><h4 class="code-header">fn <a href="#tymethod.split_at" class="fnname">split_at</a>(self, index: usize) -&gt; (Self, Self)</h4></section></summary><div class="docblock"><p>Split into two producers; one produces items <code>0..index</code>, the
other <code>index..N</code>. Index must be less than or equal to <code>N</code>.</p>
</div></details></div><h2 id="provided-methods" class="small-section-header">Provided Methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.min_len" class="method has-srclink"><a class="srclink rightside" href="../../../src/rayon/iter/plumbing/mod.rs.html#81-83">source</a><h4 class="code-header">fn <a href="#method.min_len" class="fnname">min_len</a>(&amp;self) -&gt; usize</h4></section></summary><div class="docblock"><p>The minimum number of items that we will process
sequentially. Defaults to 1, which means that we will split
all the way down to a single item. This can be raised higher
using the <a href="../trait.IndexedParallelIterator.html#method.with_min_len"><code>with_min_len</code></a> method, which will force us to
create sequential tasks at a larger granularity. Note that
Rayon automatically normally attempts to adjust the size of
parallel splits to reduce overhead, so this should not be
needed.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.max_len" class="method has-srclink"><a class="srclink rightside" href="../../../src/rayon/iter/plumbing/mod.rs.html#94-96">source</a><h4 class="code-header">fn <a href="#method.max_len" class="fnname">max_len</a>(&amp;self) -&gt; usize</h4></section></summary><div class="docblock"><p>The maximum number of items that we will process
sequentially. Defaults to MAX, which means that we can choose
not to split at all. This can be lowered using the
<a href="../trait.IndexedParallelIterator.html#method.with_max_len"><code>with_max_len</code></a> method, which will force us to create more
parallel tasks. Note that Rayon automatically normally
attempts to adjust the size of parallel splits to reduce
overhead, so this should not be needed.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fold_with" class="method has-srclink"><a class="srclink rightside" href="../../../src/rayon/iter/plumbing/mod.rs.html#106-111">source</a><h4 class="code-header">fn <a href="#method.fold_with" class="fnname">fold_with</a>&lt;F&gt;(self, folder: F) -&gt; F<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="trait.Folder.html" title="trait rayon::iter::plumbing::Folder">Folder</a>&lt;Self::<a class="associatedtype" href="trait.Producer.html#associatedtype.Item" title="type rayon::iter::plumbing::Producer::Item">Item</a>&gt;,</span></h4></section></summary><div class="docblock"><p>Iterate the producer, feeding each element to <code>folder</code>, and
stop when the folder is full (or all elements have been consumed).</p>
<p>The provided implementation is sufficient for most iterables.</p>
</div></details></div><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div id="implementors-list"></div><script src="../../../implementors/rayon/iter/plumbing/trait.Producer.js" async></script></section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="rayon" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>