296 lines
36 KiB
HTML
296 lines
36 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="API documentation for the Rust `iter` mod in crate `nom`."><meta name="keywords" content="rust, rustlang, rust-lang, iter"><title>nom::lib::std::iter - Rust</title><link rel="stylesheet" type="text/css" href="../../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../../dark.css"><link rel="stylesheet" type="text/css" href="../../../../light.css" id="themeStyle"><script src="../../../../storage.js"></script><noscript><link rel="stylesheet" href="../../../../noscript.css"></noscript><link rel="shortcut icon" href="../../../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../../../nom/index.html'><div class='logo-container'><img src='../../../../rust-logo.png' alt='logo'></div></a><p class='location'>Module iter</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'><a href='../../../index.html'>nom</a>::<wbr><a href='../../index.html'>lib</a>::<wbr><a href='../index.html'>std</a></p><script>window.sidebarCurrent = {name: 'iter', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../../../../settings.html"><img src="../../../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>−</span>]</a></span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/lib.rs.html#229' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../../index.html'>nom</a>::<wbr><a href='../../index.html'>lib</a>::<wbr><a href='../index.html'>std</a>::<wbr><a class="mod" href=''>iter</a></span></h1><div class='docblock'><p>Composable external iteration.</p>
|
||
<p>If you've found yourself with a collection of some kind, and needed to
|
||
perform an operation on the elements of said collection, you'll quickly run
|
||
into 'iterators'. Iterators are heavily used in idiomatic Rust code, so
|
||
it's worth becoming familiar with them.</p>
|
||
<p>Before explaining more, let's talk about how this module is structured:</p>
|
||
<h1 id="organization" class="section-header"><a href="#organization">Organization</a></h1>
|
||
<p>This module is largely organized by type:</p>
|
||
<ul>
|
||
<li><a href="#traits">Traits</a> are the core portion: these traits define what kind of iterators
|
||
exist and what you can do with them. The methods of these traits are worth
|
||
putting some extra study time into.</li>
|
||
<li><a href="#functions">Functions</a> provide some helpful ways to create some basic iterators.</li>
|
||
<li><a href="#structs">Structs</a> are often the return types of the various methods on this
|
||
module's traits. You'll usually want to look at the method that creates
|
||
the <code>struct</code>, rather than the <code>struct</code> itself. For more detail about why,
|
||
see '<a href="#implementing-iterator">Implementing Iterator</a>'.</li>
|
||
</ul>
|
||
<p>That's it! Let's dig into iterators.</p>
|
||
<h1 id="iterator" class="section-header"><a href="#iterator">Iterator</a></h1>
|
||
<p>The heart and soul of this module is the <a href="trait.Iterator.html"><code>Iterator</code></a> trait. The core of
|
||
<a href="trait.Iterator.html"><code>Iterator</code></a> looks like this:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">trait</span> <span class="ident">Iterator</span> {
|
||
<span class="kw">type</span> <span class="ident">Item</span>;
|
||
<span class="kw">fn</span> <span class="ident">next</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="prelude-ty">Option</span><span class="op"><</span><span class="self">Self</span>::<span class="ident">Item</span><span class="op">></span>;
|
||
}</pre></div>
|
||
<p>An iterator has a method, <a href="trait.Iterator.html#tymethod.next"><code>next</code></a>, which when called, returns an
|
||
<a href="../../std/option/enum.Option.html"><code>Option</code></a><code><Item></code>. <a href="trait.Iterator.html#tymethod.next"><code>next</code></a> will return <code>Some(Item)</code> as long as there
|
||
are elements, and once they've all been exhausted, will return <code>None</code> to
|
||
indicate that iteration is finished. Individual iterators may choose to
|
||
resume iteration, and so calling <a href="trait.Iterator.html#tymethod.next"><code>next</code></a> again may or may not eventually
|
||
start returning <code>Some(Item)</code> again at some point (for example, see <a href="../../std/sync/mpsc/struct.TryIter.html"><code>TryIter</code></a>).</p>
|
||
<p><a href="trait.Iterator.html"><code>Iterator</code></a>'s full definition includes a number of other methods as well,
|
||
but they are default methods, built on top of <a href="trait.Iterator.html#tymethod.next"><code>next</code></a>, and so you get
|
||
them for free.</p>
|
||
<p>Iterators are also composable, and it's common to chain them together to do
|
||
more complex forms of processing. See the <a href="#adapters">Adapters</a> section
|
||
below for more details.</p>
|
||
<h1 id="the-three-forms-of-iteration" class="section-header"><a href="#the-three-forms-of-iteration">The three forms of iteration</a></h1>
|
||
<p>There are three common methods which can create iterators from a collection:</p>
|
||
<ul>
|
||
<li><code>iter()</code>, which iterates over <code>&T</code>.</li>
|
||
<li><code>iter_mut()</code>, which iterates over <code>&mut T</code>.</li>
|
||
<li><code>into_iter()</code>, which iterates over <code>T</code>.</li>
|
||
</ul>
|
||
<p>Various things in the standard library may implement one or more of the
|
||
three, where appropriate.</p>
|
||
<h1 id="implementing-iterator" class="section-header"><a href="#implementing-iterator">Implementing Iterator</a></h1>
|
||
<p>Creating an iterator of your own involves two steps: creating a <code>struct</code> to
|
||
hold the iterator's state, and then <code>impl</code>ementing <a href="trait.Iterator.html"><code>Iterator</code></a> for that
|
||
<code>struct</code>. This is why there are so many <code>struct</code>s in this module: there is
|
||
one for each iterator and iterator adapter.</p>
|
||
<p>Let's make an iterator named <code>Counter</code> which counts from <code>1</code> to <code>5</code>:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="comment">// First, the struct:</span>
|
||
|
||
<span class="doccomment">/// An iterator which counts from one to five</span>
|
||
<span class="kw">struct</span> <span class="ident">Counter</span> {
|
||
<span class="ident">count</span>: <span class="ident">usize</span>,
|
||
}
|
||
|
||
<span class="comment">// we want our count to start at one, so let's add a new() method to help.</span>
|
||
<span class="comment">// This isn't strictly necessary, but is convenient. Note that we start</span>
|
||
<span class="comment">// `count` at zero, we'll see why in `next()`'s implementation below.</span>
|
||
<span class="kw">impl</span> <span class="ident">Counter</span> {
|
||
<span class="kw">fn</span> <span class="ident">new</span>() <span class="op">-</span><span class="op">></span> <span class="ident">Counter</span> {
|
||
<span class="ident">Counter</span> { <span class="ident">count</span>: <span class="number">0</span> }
|
||
}
|
||
}
|
||
|
||
<span class="comment">// Then, we implement `Iterator` for our `Counter`:</span>
|
||
|
||
<span class="kw">impl</span> <span class="ident">Iterator</span> <span class="kw">for</span> <span class="ident">Counter</span> {
|
||
<span class="comment">// we will be counting with usize</span>
|
||
<span class="kw">type</span> <span class="ident">Item</span> <span class="op">=</span> <span class="ident">usize</span>;
|
||
|
||
<span class="comment">// next() is the only required method</span>
|
||
<span class="kw">fn</span> <span class="ident">next</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="prelude-ty">Option</span><span class="op"><</span><span class="self">Self</span>::<span class="ident">Item</span><span class="op">></span> {
|
||
<span class="comment">// Increment our count. This is why we started at zero.</span>
|
||
<span class="self">self</span>.<span class="ident">count</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
|
||
<span class="comment">// Check to see if we've finished counting or not.</span>
|
||
<span class="kw">if</span> <span class="self">self</span>.<span class="ident">count</span> <span class="op"><</span> <span class="number">6</span> {
|
||
<span class="prelude-val">Some</span>(<span class="self">self</span>.<span class="ident">count</span>)
|
||
} <span class="kw">else</span> {
|
||
<span class="prelude-val">None</span>
|
||
}
|
||
}
|
||
}
|
||
|
||
<span class="comment">// And now we can use it!</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">counter</span> <span class="op">=</span> <span class="ident">Counter</span>::<span class="ident">new</span>();
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">counter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="number">1</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">counter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="number">2</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">counter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="number">3</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">counter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="number">4</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">counter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="number">5</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">counter</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>);</pre></div>
|
||
<p>Calling <a href="trait.Iterator.html#tymethod.next"><code>next</code></a> this way gets repetitive. Rust has a construct which can
|
||
call <a href="trait.Iterator.html#tymethod.next"><code>next</code></a> on your iterator, until it reaches <code>None</code>. Let's go over that
|
||
next.</p>
|
||
<p>Also note that <code>Iterator</code> provides a default implementation of methods such as <code>nth</code> and <code>fold</code>
|
||
which call <code>next</code> internally. However, it is also possible to write a custom implementation of
|
||
methods like <code>nth</code> and <code>fold</code> if an iterator can compute them more efficiently without calling
|
||
<code>next</code>.</p>
|
||
<h1 id="for-loops-and-intoiterator" class="section-header"><a href="#for-loops-and-intoiterator">for Loops and IntoIterator</a></h1>
|
||
<p>Rust's <code>for</code> loop syntax is actually sugar for iterators. Here's a basic
|
||
example of <code>for</code>:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">values</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
||
|
||
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">values</span> {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>);
|
||
}</pre></div>
|
||
<p>This will print the numbers one through five, each on their own line. But
|
||
you'll notice something here: we never called anything on our vector to
|
||
produce an iterator. What gives?</p>
|
||
<p>There's a trait in the standard library for converting something into an
|
||
iterator: <a href="trait.IntoIterator.html"><code>IntoIterator</code></a>. This trait has one method, <a href="trait.IntoIterator.html#tymethod.into_iter"><code>into_iter</code></a>,
|
||
which converts the thing implementing <a href="trait.IntoIterator.html"><code>IntoIterator</code></a> into an iterator.
|
||
Let's take a look at that <code>for</code> loop again, and what the compiler converts
|
||
it into:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">values</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
||
|
||
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">values</span> {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>);
|
||
}</pre></div>
|
||
<p>Rust de-sugars this into:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">values</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
||
{
|
||
<span class="kw">let</span> <span class="ident">result</span> <span class="op">=</span> <span class="kw">match</span> <span class="ident">IntoIterator</span>::<span class="ident">into_iter</span>(<span class="ident">values</span>) {
|
||
<span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span><span class="op">></span> <span class="kw">loop</span> {
|
||
<span class="kw">let</span> <span class="ident">next</span>;
|
||
<span class="kw">match</span> <span class="ident">iter</span>.<span class="ident">next</span>() {
|
||
<span class="prelude-val">Some</span>(<span class="ident">val</span>) <span class="op">=</span><span class="op">></span> <span class="ident">next</span> <span class="op">=</span> <span class="ident">val</span>,
|
||
<span class="prelude-val">None</span> <span class="op">=</span><span class="op">></span> <span class="kw">break</span>,
|
||
};
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">next</span>;
|
||
<span class="kw">let</span> () <span class="op">=</span> { <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>); };
|
||
},
|
||
};
|
||
<span class="ident">result</span>
|
||
}</pre></div>
|
||
<p>First, we call <code>into_iter()</code> on the value. Then, we match on the iterator
|
||
that returns, calling <a href="trait.Iterator.html#tymethod.next"><code>next</code></a> over and over until we see a <code>None</code>. At
|
||
that point, we <code>break</code> out of the loop, and we're done iterating.</p>
|
||
<p>There's one more subtle bit here: the standard library contains an
|
||
interesting implementation of <a href="trait.IntoIterator.html"><code>IntoIterator</code></a>:</p>
|
||
|
||
<div class='information'><div class='tooltip ignore'>ⓘ<span class='tooltiptext'>This example is not tested</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore">
|
||
<span class="kw">impl</span><span class="op"><</span><span class="ident">I</span>: <span class="ident">Iterator</span><span class="op">></span> <span class="ident">IntoIterator</span> <span class="kw">for</span> <span class="ident">I</span></pre></div>
|
||
<p>In other words, all <a href="trait.Iterator.html"><code>Iterator</code></a>s implement <a href="trait.IntoIterator.html"><code>IntoIterator</code></a>, by just
|
||
returning themselves. This means two things:</p>
|
||
<ol>
|
||
<li>If you're writing an <a href="trait.Iterator.html"><code>Iterator</code></a>, you can use it with a <code>for</code> loop.</li>
|
||
<li>If you're creating a collection, implementing <a href="trait.IntoIterator.html"><code>IntoIterator</code></a> for it
|
||
will allow your collection to be used with the <code>for</code> loop.</li>
|
||
</ol>
|
||
<h1 id="adapters" class="section-header"><a href="#adapters">Adapters</a></h1>
|
||
<p>Functions which take an <a href="trait.Iterator.html"><code>Iterator</code></a> and return another <a href="trait.Iterator.html"><code>Iterator</code></a> are
|
||
often called 'iterator adapters', as they're a form of the 'adapter
|
||
pattern'.</p>
|
||
<p>Common iterator adapters include <a href="trait.Iterator.html#method.map"><code>map</code></a>, <a href="trait.Iterator.html#method.take"><code>take</code></a>, and <a href="trait.Iterator.html#method.filter"><code>filter</code></a>.
|
||
For more, see their documentation.</p>
|
||
<p>If an iterator adapter panics, the iterator will be in an unspecified (but
|
||
memory safe) state. This state is also not guaranteed to stay the same
|
||
across versions of Rust, so you should avoid relying on the exact values
|
||
returned by an iterator which panicked.</p>
|
||
<h1 id="laziness" class="section-header"><a href="#laziness">Laziness</a></h1>
|
||
<p>Iterators (and iterator <a href="#adapters">adapters</a>) are <em>lazy</em>. This means that
|
||
just creating an iterator doesn't <em>do</em> a whole lot. Nothing really happens
|
||
until you call <a href="trait.Iterator.html#tymethod.next"><code>next</code></a>. This is sometimes a source of confusion when
|
||
creating an iterator solely for its side effects. For example, the <a href="trait.Iterator.html#method.map"><code>map</code></a>
|
||
method calls a closure on each element it iterates over:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
||
<span class="ident">v</span>.<span class="ident">iter</span>().<span class="ident">map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>));</pre></div>
|
||
<p>This will not print any values, as we only created an iterator, rather than
|
||
using it. The compiler will warn us about this kind of behavior:</p>
|
||
<pre><code class="language-text">warning: unused result that must be used: iterators are lazy and
|
||
do nothing unless consumed
|
||
</code></pre>
|
||
<p>The idiomatic way to write a <a href="trait.Iterator.html#method.map"><code>map</code></a> for its side effects is to use a
|
||
<code>for</code> loop or call the <a href="trait.Iterator.html#method.for_each"><code>for_each</code></a> method:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
||
|
||
<span class="ident">v</span>.<span class="ident">iter</span>().<span class="ident">for_each</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>));
|
||
<span class="comment">// or</span>
|
||
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="kw-2">&</span><span class="ident">v</span> {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>);
|
||
}</pre></div>
|
||
<p>Another common way to evaluate an iterator is to use the <a href="trait.Iterator.html#method.collect"><code>collect</code></a>
|
||
method to produce a new collection.</p>
|
||
<h1 id="infinity" class="section-header"><a href="#infinity">Infinity</a></h1>
|
||
<p>Iterators do not have to be finite. As an example, an open-ended range is
|
||
an infinite iterator:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">numbers</span> <span class="op">=</span> <span class="number">0</span>..;</pre></div>
|
||
<p>It is common to use the <a href="trait.Iterator.html#method.take"><code>take</code></a> iterator adapter to turn an infinite
|
||
iterator into a finite one:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">numbers</span> <span class="op">=</span> <span class="number">0</span>..;
|
||
<span class="kw">let</span> <span class="ident">five_numbers</span> <span class="op">=</span> <span class="ident">numbers</span>.<span class="ident">take</span>(<span class="number">5</span>);
|
||
|
||
<span class="kw">for</span> <span class="ident">number</span> <span class="kw">in</span> <span class="ident">five_numbers</span> {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">number</span>);
|
||
}</pre></div>
|
||
<p>This will print the numbers <code>0</code> through <code>4</code>, each on their own line.</p>
|
||
<p>Bear in mind that methods on infinite iterators, even those for which a
|
||
result can be determined mathematically in finite time, may not terminate.
|
||
Specifically, methods such as <a href="trait.Iterator.html#method.min"><code>min</code></a>, which in the general case require
|
||
traversing every element in the iterator, are likely not to return
|
||
successfully for any infinite iterators.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">ones</span> <span class="op">=</span> <span class="ident">std</span>::<span class="ident">iter</span>::<span class="ident">repeat</span>(<span class="number">1</span>);
|
||
<span class="kw">let</span> <span class="ident">least</span> <span class="op">=</span> <span class="ident">ones</span>.<span class="ident">min</span>().<span class="ident">unwrap</span>(); <span class="comment">// Oh no! An infinite loop!</span>
|
||
<span class="comment">// `ones.min()` causes an infinite loop, so we won't reach this point!</span>
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"The smallest number one is {}."</span>, <span class="ident">least</span>);</pre></div>
|
||
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
|
||
<table><tr class='module-item'><td><a class="struct" href="struct.Chain.html" title='nom::lib::std::iter::Chain struct'>Chain</a></td><td class='docblock-short'><p>An iterator that links two iterators together, in a chain.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Cloned.html" title='nom::lib::std::iter::Cloned struct'>Cloned</a></td><td class='docblock-short'><p>An iterator that clones the elements of an underlying iterator.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Copied.html" title='nom::lib::std::iter::Copied struct'>Copied</a></td><td class='docblock-short'><p>An iterator that copies the elements of an underlying iterator.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Cycle.html" title='nom::lib::std::iter::Cycle struct'>Cycle</a></td><td class='docblock-short'><p>An iterator that repeats endlessly.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Empty.html" title='nom::lib::std::iter::Empty struct'>Empty</a></td><td class='docblock-short'><p>An iterator that yields nothing.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Enumerate.html" title='nom::lib::std::iter::Enumerate struct'>Enumerate</a></td><td class='docblock-short'><p>An iterator that yields the current count and the element during iteration.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Filter.html" title='nom::lib::std::iter::Filter struct'>Filter</a></td><td class='docblock-short'><p>An iterator that filters the elements of <code>iter</code> with <code>predicate</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.FilterMap.html" title='nom::lib::std::iter::FilterMap struct'>FilterMap</a></td><td class='docblock-short'><p>An iterator that uses <code>f</code> to both filter and map elements from <code>iter</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.FlatMap.html" title='nom::lib::std::iter::FlatMap struct'>FlatMap</a></td><td class='docblock-short'><p>An iterator that maps each element to an iterator, and yields the elements
|
||
of the produced iterators.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Flatten.html" title='nom::lib::std::iter::Flatten struct'>Flatten</a></td><td class='docblock-short'><p>An iterator that flattens one level of nesting in an iterator of things
|
||
that can be turned into iterators.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.FromFn.html" title='nom::lib::std::iter::FromFn struct'>FromFn</a></td><td class='docblock-short'><p>An iterator where each iteration calls the provided closure <code>F: FnMut() -> Option<T></code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Fuse.html" title='nom::lib::std::iter::Fuse struct'>Fuse</a></td><td class='docblock-short'><p>An iterator that yields <code>None</code> forever after the underlying iterator
|
||
yields <code>None</code> once.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Inspect.html" title='nom::lib::std::iter::Inspect struct'>Inspect</a></td><td class='docblock-short'><p>An iterator that calls a function with a reference to each element before
|
||
yielding it.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Map.html" title='nom::lib::std::iter::Map struct'>Map</a></td><td class='docblock-short'><p>An iterator that maps the values of <code>iter</code> with <code>f</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Once.html" title='nom::lib::std::iter::Once struct'>Once</a></td><td class='docblock-short'><p>An iterator that yields an element exactly once.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.OnceWith.html" title='nom::lib::std::iter::OnceWith struct'>OnceWith</a></td><td class='docblock-short'><p>An iterator that yields a single element of type <code>A</code> by
|
||
applying the provided closure <code>F: FnOnce() -> A</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Peekable.html" title='nom::lib::std::iter::Peekable struct'>Peekable</a></td><td class='docblock-short'><p>An iterator with a <code>peek()</code> that returns an optional reference to the next
|
||
element.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Repeat.html" title='nom::lib::std::iter::Repeat struct'>Repeat</a></td><td class='docblock-short'><p>An iterator that repeats an element endlessly.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.RepeatWith.html" title='nom::lib::std::iter::RepeatWith struct'>RepeatWith</a></td><td class='docblock-short'><p>An iterator that repeats elements of type <code>A</code> endlessly by
|
||
applying the provided closure <code>F: FnMut() -> A</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Rev.html" title='nom::lib::std::iter::Rev struct'>Rev</a></td><td class='docblock-short'><p>A double-ended iterator with the direction inverted.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Scan.html" title='nom::lib::std::iter::Scan struct'>Scan</a></td><td class='docblock-short'><p>An iterator to maintain state while iterating another iterator.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Skip.html" title='nom::lib::std::iter::Skip struct'>Skip</a></td><td class='docblock-short'><p>An iterator that skips over <code>n</code> elements of <code>iter</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.SkipWhile.html" title='nom::lib::std::iter::SkipWhile struct'>SkipWhile</a></td><td class='docblock-short'><p>An iterator that rejects elements while <code>predicate</code> returns <code>true</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.StepBy.html" title='nom::lib::std::iter::StepBy struct'>StepBy</a></td><td class='docblock-short'><p>An iterator for stepping iterators by a custom amount.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Successors.html" title='nom::lib::std::iter::Successors struct'>Successors</a></td><td class='docblock-short'><p>An new iterator where each successive item is computed based on the preceding one.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Take.html" title='nom::lib::std::iter::Take struct'>Take</a></td><td class='docblock-short'><p>An iterator that only iterates over the first <code>n</code> iterations of <code>iter</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.TakeWhile.html" title='nom::lib::std::iter::TakeWhile struct'>TakeWhile</a></td><td class='docblock-short'><p>An iterator that only accepts elements while <code>predicate</code> returns <code>true</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Zip.html" title='nom::lib::std::iter::Zip struct'>Zip</a></td><td class='docblock-short'><p>An iterator that iterates two other iterators simultaneously.</p>
|
||
</td></tr><tr class='unstable module-item'><td><a class="struct" href="struct.MapWhile.html" title='nom::lib::std::iter::MapWhile struct'>MapWhile</a></td><td class='docblock-short'><span class="stab unstable">Experimental</span><p>An iterator that only accepts elements while <code>predicate</code> returns <code>Some(_)</code>.</p>
|
||
</td></tr></table><h2 id='traits' class='section-header'><a href="#traits">Traits</a></h2>
|
||
<table><tr class='module-item'><td><a class="trait" href="trait.DoubleEndedIterator.html" title='nom::lib::std::iter::DoubleEndedIterator trait'>DoubleEndedIterator</a></td><td class='docblock-short'><p>An iterator able to yield elements from both ends.</p>
|
||
</td></tr><tr class='module-item'><td><a class="trait" href="trait.ExactSizeIterator.html" title='nom::lib::std::iter::ExactSizeIterator trait'>ExactSizeIterator</a></td><td class='docblock-short'><p>An iterator that knows its exact length.</p>
|
||
</td></tr><tr class='module-item'><td><a class="trait" href="trait.Extend.html" title='nom::lib::std::iter::Extend trait'>Extend</a></td><td class='docblock-short'><p>Extend a collection with the contents of an iterator.</p>
|
||
</td></tr><tr class='module-item'><td><a class="trait" href="trait.FromIterator.html" title='nom::lib::std::iter::FromIterator trait'>FromIterator</a></td><td class='docblock-short'><p>Conversion from an <code>Iterator</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="trait" href="trait.FusedIterator.html" title='nom::lib::std::iter::FusedIterator trait'>FusedIterator</a></td><td class='docblock-short'><p>An iterator that always continues to yield <code>None</code> when exhausted.</p>
|
||
</td></tr><tr class='module-item'><td><a class="trait" href="trait.IntoIterator.html" title='nom::lib::std::iter::IntoIterator trait'>IntoIterator</a></td><td class='docblock-short'><p>Conversion into an <code>Iterator</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="trait" href="trait.Iterator.html" title='nom::lib::std::iter::Iterator trait'>Iterator</a></td><td class='docblock-short'><p>An interface for dealing with iterators.</p>
|
||
</td></tr><tr class='module-item'><td><a class="trait" href="trait.Product.html" title='nom::lib::std::iter::Product trait'>Product</a></td><td class='docblock-short'><p>Trait to represent types that can be created by multiplying elements of an
|
||
iterator.</p>
|
||
</td></tr><tr class='module-item'><td><a class="trait" href="trait.Sum.html" title='nom::lib::std::iter::Sum trait'>Sum</a></td><td class='docblock-short'><p>Trait to represent types that can be created by summing up an iterator.</p>
|
||
</td></tr><tr class='unstable module-item'><td><a class="trait" href="trait.Step.html" title='nom::lib::std::iter::Step trait'>Step</a></td><td class='docblock-short'><span class="stab unstable">Experimental</span><p>Objects that can be stepped over in both directions.</p>
|
||
</td></tr><tr class='unstable module-item'><td><a class="trait" href="trait.TrustedLen.html" title='nom::lib::std::iter::TrustedLen trait'>TrustedLen</a></td><td class='docblock-short'><span class="stab unstable">Experimental</span><p>An iterator that reports an accurate length using size_hint.</p>
|
||
</td></tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
|
||
<table><tr class='module-item'><td><a class="fn" href="fn.empty.html" title='nom::lib::std::iter::empty fn'>empty</a></td><td class='docblock-short'><p>Creates an iterator that yields nothing.</p>
|
||
</td></tr><tr class='module-item'><td><a class="fn" href="fn.from_fn.html" title='nom::lib::std::iter::from_fn fn'>from_fn</a></td><td class='docblock-short'><p>Creates a new iterator where each iteration calls the provided closure
|
||
<code>F: FnMut() -> Option<T></code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="fn" href="fn.once.html" title='nom::lib::std::iter::once fn'>once</a></td><td class='docblock-short'><p>Creates an iterator that yields an element exactly once.</p>
|
||
</td></tr><tr class='module-item'><td><a class="fn" href="fn.once_with.html" title='nom::lib::std::iter::once_with fn'>once_with</a></td><td class='docblock-short'><p>Creates an iterator that lazily generates a value exactly once by invoking
|
||
the provided closure.</p>
|
||
</td></tr><tr class='module-item'><td><a class="fn" href="fn.repeat.html" title='nom::lib::std::iter::repeat fn'>repeat</a></td><td class='docblock-short'><p>Creates a new iterator that endlessly repeats a single element.</p>
|
||
</td></tr><tr class='module-item'><td><a class="fn" href="fn.repeat_with.html" title='nom::lib::std::iter::repeat_with fn'>repeat_with</a></td><td class='docblock-short'><p>Creates a new iterator that repeats elements of type <code>A</code> endlessly by
|
||
applying the provided closure, the repeater, <code>F: FnMut() -> A</code>.</p>
|
||
</td></tr><tr class='module-item'><td><a class="fn" href="fn.successors.html" title='nom::lib::std::iter::successors fn'>successors</a></td><td class='docblock-short'><p>Creates a new iterator where each successive item is computed based on the preceding one.</p>
|
||
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../../../../";window.currentCrate = "nom";</script><script src="../../../../aliases.js"></script><script src="../../../../main.js"></script><script defer src="../../../../search-index.js"></script></body></html> |