blob: ee93494fc9e31e7c5cb432e767cdcb25744aead2 [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="An iterator that generalizes .zip() and allows running multiple iterators in lockstep."><meta name="keywords" content="rust, rustlang, rust-lang, multizip"><title>multizip in itertools - 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 fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../itertools/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="../itertools/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><div class="sidebar-elems"><h2><a href="index.html">In itertools</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">Function <a href="index.html">itertools</a>::<wbr><a class="fn" href="#">multizip</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/itertools/ziptuple.rs.html#40-45">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 fn"><code>pub fn multizip&lt;T, U&gt;(t: U) -&gt; <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;T&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A,)&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;A&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A,)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item,);</span><span class="where fmt-newline">impl&lt;A, B&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item);</span><span class="where fmt-newline">impl&lt;A, B, C&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B, C)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item, C::Item);</span><span class="where fmt-newline">impl&lt;A, B, C, D&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B, C, D)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;D: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item, C::Item, D::Item);</span><span class="where fmt-newline">impl&lt;A, B, C, D, E&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B, C, D, E)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;D: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item, C::Item, D::Item, E::Item);</span><span class="where fmt-newline">impl&lt;A, B, C, D, E, F&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B, C, D, E, F)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;D: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item);</span><span class="where fmt-newline">impl&lt;A, B, C, D, E, F, G&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B, C, D, E, F, G)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;D: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;G: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item);</span><span class="where fmt-newline">impl&lt;A, B, C, D, E, F, G, H&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B, C, D, E, F, G, H)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;D: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;G: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;H: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item, H::Item);</span><span class="where fmt-newline">impl&lt;A, B, C, D, E, F, G, H, I&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B, C, D, E, F, G, H, I)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;D: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;G: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;H: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item, H::Item, I::Item);</span><span class="where fmt-newline">impl&lt;A, B, C, D, E, F, G, H, I, J&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B, C, D, E, F, G, H, I, J)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;D: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;G: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;H: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;J: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item, H::Item, I::Item, J::Item);</span><span class="where fmt-newline">impl&lt;A, B, C, D, E, F, G, H, I, J, K&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B, C, D, E, F, G, H, I, J, K)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;D: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;G: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;H: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;J: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;K: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item, H::Item, I::Item, J::Item, K::Item);</span><span class="where fmt-newline">impl&lt;A, B, C, D, E, F, G, H, I, J, K, L&gt; Iterator for <a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;(A, B, C, D, E, F, G, H, I, J, K, L)&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;A: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;D: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;G: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;H: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;J: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;K: Iterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;L: Iterator,</span></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item, H::Item, I::Item, J::Item, K::Item, L::Item);</span></code></span></span></span></span><span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;<a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;T&gt;: From&lt;U&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a class="struct" href="structs/struct.Zip.html" title="struct itertools::structs::Zip">Zip</a>&lt;T&gt;: Iterator,</span></code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An iterator that generalizes <em>.zip()</em> and allows running multiple iterators in lockstep.</p>
<p>The iterator <code>Zip&lt;(I, J, ..., M)&gt;</code> is formed from a tuple of iterators (or values that
implement [<code>IntoIterator</code>]) and yields elements
until any of the subiterators yields <code>None</code>.</p>
<p>The iterator element type is a tuple like like <code>(A, B, ..., E)</code> where <code>A</code> to <code>E</code> are the
element types of the subiterator.</p>
<p><strong>Note:</strong> The result of this macro is a value of a named type (<code>Zip&lt;(I, J, ..)&gt;</code> of each component iterator <code>I, J, ...</code>) if each component iterator is
nameable.</p>
<p>Prefer <a href="macro.izip.html"><code>izip!()</code></a> over <code>multizip</code> for the performance benefits of using the
standard library <code>.zip()</code>. Prefer <code>multizip</code> if a nameable type is needed.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::multizip;
<span class="comment">// iterate over three sequences side-by-side
</span><span class="kw">let </span><span class="kw-2">mut </span>results = [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>];
<span class="kw">let </span>inputs = [<span class="number">3</span>, <span class="number">7</span>, <span class="number">9</span>, <span class="number">6</span>];
<span class="kw">for </span>(r, index, input) <span class="kw">in </span>multizip((<span class="kw-2">&amp;mut </span>results, <span class="number">0</span>..<span class="number">10</span>, <span class="kw-2">&amp;</span>inputs)) {
<span class="kw-2">*</span>r = index * <span class="number">10 </span>+ input;
}
<span class="macro">assert_eq!</span>(results, [<span class="number">0 </span>+ <span class="number">3</span>, <span class="number">10 </span>+ <span class="number">7</span>, <span class="number">29</span>, <span class="number">36</span>]);</code></pre></div>
</div></details></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="itertools" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>