<!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 `TrustedLen` trait in crate `std`."> <meta name="keywords" content="rust, rustlang, rust-lang, TrustedLen"> <title>std::iter::TrustedLen - 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="../../main.css" id="themeStyle"> <script src="../../storage.js"></script> <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico"> </head> <body class="rustdoc trait"> <!--[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='../../std/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a> <p class='location'>Trait TrustedLen</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='../index.html'>std</a>::<wbr><a href='index.html'>iter</a></p><script>window.sidebarCurrent = {name: 'TrustedLen', ty: 'trait', 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 js-only"> <div class="search-container"> <input class="search-input" name="search" autocomplete="off" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"> </div> </form> </nav> <section id='main' class="content"> <h1 class='fqn'><span class='in-band'>Trait <a href='../index.html'>std</a>::<wbr><a href='index.html'>iter</a>::<wbr><a class="trait" href=''>TrustedLen</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version '></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='../../src/core/iter/traits.rs.html#988' title='goto source code'>[src]</a></span></h1> <pre class='rust trait'>pub unsafe trait TrustedLen: <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> { }</pre><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API. (<code>trusted_len </code><a href="https://github.com/rust-lang/rust/issues/37572">#37572</a>)</div></div><div class='docblock'><p>An iterator that reports an accurate length using size_hint.</p> <p>The iterator reports a size hint where it is either exact (lower bound is equal to upper bound), or the upper bound is <a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a>. The upper bound must only be <a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a> if the actual iterator length is larger than <a href="../../std/usize/constant.MAX.html"><code>usize::MAX</code></a>. In that case, the lower bound must be <a href="../../std/usize/constant.MAX.html"><code>usize::MAX</code></a>, resulting in a <a href="../../std/iter/trait.Iterator.html#method.size_hint"><code>.size_hint</code></a> of <code>(usize::MAX, None)</code>.</p> <p>The iterator must produce exactly the number of elements it reported or diverge before reaching the end.</p> <h1 id="safety" class="section-header"><a href="#safety">Safety</a></h1> <p>This trait must only be implemented when the contract is upheld. Consumers of this trait must inspect <a href="../../std/iter/trait.Iterator.html#method.size_hint"><code>.size_hint</code></a>’s upper bound.</p> </div> <h2 id='implementors' class='small-section-header'> Implementors<a href='#implementors' class='anchor'></a> </h2> <ul class='item-list' id='implementors-list'> <li><div class='out-of-band'><a class='srclink' href='../../src/core/option.rs.html#1140' title='goto source code'>[src]</a></div><code>impl<A> TrustedLen for std::option::<a class="struct" href="../../std/option/struct.IntoIter.html" title="struct std::option::IntoIter">IntoIter</a><A></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/traits.rs.html#991' title='goto source code'>[src]</a></div><code>impl<'a, I> TrustedLen for <a class="primitive" href="../primitive.reference.html">&'a mut </a>I <span class="where fmt-newline">where<br> I: <a class="trait" href="../../std/iter/trait.TrustedLen.html" title="trait std::iter::TrustedLen">TrustedLen</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/slice/mod.rs.html#1468' title='goto source code'>[src]</a></div><code>impl<'a, T> TrustedLen for std::slice::<a class="struct" href="../../std/slice/struct.Iter.html" title="struct std::slice::Iter">Iter</a><'a, T></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/slice/mod.rs.html#1596' title='goto source code'>[src]</a></div><code>impl<'a, T> TrustedLen for std::slice::<a class="struct" href="../../std/slice/struct.IterMut.html" title="struct std::slice::IterMut">IterMut</a><'a, T></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#208' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a><<a class="primitive" href="../primitive.i32.html">i32</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/mod.rs.html#1010-1012' title='goto source code'>[src]</a></div><code>impl<A, B> TrustedLen for <a class="struct" href="../../std/iter/struct.Chain.html" title="struct std::iter::Chain">Chain</a><A, B> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../std/iter/trait.TrustedLen.html" title="trait std::iter::TrustedLen">TrustedLen</a>,<br> B: <a class="trait" href="../../std/iter/trait.TrustedLen.html" title="trait std::iter::TrustedLen">TrustedLen</a><Item = <A as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>>::<a class="type" href="../../std/iter/trait.Iterator.html#associatedtype.Item" title="type std::iter::Iterator::Item">Item</a>>, </span></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#208' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a><<a class="primitive" href="../primitive.usize.html">usize</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/str/mod.rs.html#824' title='goto source code'>[src]</a></div><code>impl<'a> TrustedLen for <a class="struct" href="../../std/str/struct.Bytes.html" title="struct std::str::Bytes">Bytes</a><'a></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#199' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a><<a class="primitive" href="../primitive.u8.html">u8</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#199' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a><<a class="primitive" href="../primitive.i8.html">i8</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/option.rs.html#1058' title='goto source code'>[src]</a></div><code>impl<'a, A> TrustedLen for std::option::<a class="struct" href="../../std/option/struct.Iter.html" title="struct std::option::Iter">Iter</a><'a, A></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/mod.rs.html#1232-1234' title='goto source code'>[src]</a></div><code>impl<A, B> TrustedLen for <a class="struct" href="../../std/iter/struct.Zip.html" title="struct std::iter::Zip">Zip</a><A, B> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../std/iter/trait.TrustedLen.html" title="trait std::iter::TrustedLen">TrustedLen</a>,<br> B: <a class="trait" href="../../std/iter/trait.TrustedLen.html" title="trait std::iter::TrustedLen">TrustedLen</a>, </span></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#199' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a><<a class="primitive" href="../primitive.usize.html">usize</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/result.rs.html#1089' title='goto source code'>[src]</a></div><code>impl<'a, A> TrustedLen for std::result::<a class="struct" href="../../std/result/struct.IterMut.html" title="struct std::result::IterMut">IterMut</a><'a, A></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#199' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a><<a class="primitive" href="../primitive.u32.html">u32</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#208' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a><<a class="primitive" href="../primitive.u64.html">u64</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#208' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a><<a class="primitive" href="../primitive.i8.html">i8</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#208' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a><<a class="primitive" href="../primitive.i64.html">i64</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/result.rs.html#1045' title='goto source code'>[src]</a></div><code>impl<'a, A> TrustedLen for std::result::<a class="struct" href="../../std/result/struct.Iter.html" title="struct std::result::Iter">Iter</a><'a, A></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#199' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a><<a class="primitive" href="../primitive.u16.html">u16</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#199' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a><<a class="primitive" href="../primitive.i64.html">i64</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#208' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a><<a class="primitive" href="../primitive.i16.html">i16</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/sources.rs.html#226' title='goto source code'>[src]</a></div><code>impl<T> TrustedLen for <a class="struct" href="../../std/iter/struct.Once.html" title="struct std::iter::Once">Once</a><T></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/sources.rs.html#48' title='goto source code'>[src]</a></div><code>impl<A> TrustedLen for <a class="struct" href="../../std/iter/struct.Repeat.html" title="struct std::iter::Repeat">Repeat</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a>, </span></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/mod.rs.html#512-513' title='goto source code'>[src]</a></div><code>impl<I> TrustedLen for <a class="struct" href="../../std/iter/struct.Rev.html" title="struct std::iter::Rev">Rev</a><I> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../std/iter/trait.TrustedLen.html" title="trait std::iter::TrustedLen">TrustedLen</a> + <a class="trait" href="../../std/iter/trait.DoubleEndedIterator.html" title="trait std::iter::DoubleEndedIterator">DoubleEndedIterator</a>, </span></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#199' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a><<a class="primitive" href="../primitive.i32.html">i32</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/mod.rs.html#620-623' title='goto source code'>[src]</a></div><code>impl<'a, I, T> TrustedLen for <a class="struct" href="../../std/iter/struct.Cloned.html" title="struct std::iter::Cloned">Cloned</a><I> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../std/iter/trait.TrustedLen.html" title="trait std::iter::TrustedLen">TrustedLen</a><Item = <a class="primitive" href="../primitive.reference.html">&'a </a>T>,<br> T: 'a + <a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a>, </span></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/option.rs.html#1102' title='goto source code'>[src]</a></div><code>impl<'a, A> TrustedLen for std::option::<a class="struct" href="../../std/option/struct.IterMut.html" title="struct std::option::IterMut">IterMut</a><'a, A></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#199' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a><<a class="primitive" href="../primitive.i16.html">i16</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#199' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a><<a class="primitive" href="../primitive.isize.html">isize</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#199' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.Range.html" title="struct std::ops::Range">Range</a><<a class="primitive" href="../primitive.u64.html">u64</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/mod.rs.html#1374-1376' title='goto source code'>[src]</a></div><code>impl<B, I, F> TrustedLen for <a class="struct" href="../../std/iter/struct.Map.html" title="struct std::iter::Map">Map</a><I, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../std/ops/trait.FnMut.html" title="trait std::ops::FnMut">FnMut</a>(<I as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>>::<a class="type" href="../../std/iter/trait.Iterator.html#associatedtype.Item" title="type std::iter::Iterator::Item">Item</a>) -> B,<br> I: <a class="trait" href="../../std/iter/trait.TrustedLen.html" title="trait std::iter::TrustedLen">TrustedLen</a>, </span></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#208' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a><<a class="primitive" href="../primitive.isize.html">isize</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#208' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a><<a class="primitive" href="../primitive.u8.html">u8</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/mod.rs.html#2340' title='goto source code'>[src]</a></div><code>impl<I> TrustedLen for <a class="struct" href="../../std/iter/struct.Take.html" title="struct std::iter::Take">Take</a><I> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../std/iter/trait.TrustedLen.html" title="trait std::iter::TrustedLen">TrustedLen</a>, </span></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#208' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a><<a class="primitive" href="../primitive.u32.html">u32</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/mod.rs.html#1787-1789' title='goto source code'>[src]</a></div><code>impl<I> TrustedLen for <a class="struct" href="../../std/iter/struct.Enumerate.html" title="struct std::iter::Enumerate">Enumerate</a><I> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../std/iter/trait.TrustedLen.html" title="trait std::iter::TrustedLen">TrustedLen</a>, </span></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/result.rs.html#1132' title='goto source code'>[src]</a></div><code>impl<A> TrustedLen for std::result::<a class="struct" href="../../std/result/struct.IntoIter.html" title="struct std::result::IntoIter">IntoIter</a><A></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/sources.rs.html#145' title='goto source code'>[src]</a></div><code>impl<T> TrustedLen for <a class="struct" href="../../std/iter/struct.Empty.html" title="struct std::iter::Empty">Empty</a><T></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#208' title='goto source code'>[src]</a></div><code>impl TrustedLen for <a class="struct" href="../../std/ops/struct.RangeInclusive.html" title="struct std::ops::RangeInclusive">RangeInclusive</a><<a class="primitive" href="../primitive.u16.html">u16</a>></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/core/iter/range.rs.html#329' title='goto source code'>[src]</a></div><code>impl<A> TrustedLen for <a class="struct" href="../../std/ops/struct.RangeFrom.html" title="struct std::ops::RangeFrom">RangeFrom</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../std/iter/trait.Step.html" title="trait std::iter::Step">Step</a>, </span></code></li> <li><div class='out-of-band'><a class='srclink' href='../../src/alloc/vec.rs.html#2411' title='goto source code'>[src]</a></div><code>impl<T> TrustedLen for std::vec::<a class="struct" href="../../std/vec/struct.IntoIter.html" title="struct std::vec::IntoIter">IntoIter</a><T></code></li> </ul><script type="text/javascript" async src="../../implementors/core/iter/traits/trait.TrustedLen.js"> </script></section> <section id='search' class="content hidden"></section> <section class="footer"></section> <aside id="help" class="hidden"> <div> <h1 class="hidden">Help</h1> <div class="shortcuts"> <h2>Keyboard Shortcuts</h2> <dl> <dt><kbd>?</kbd></dt> <dd>Show this help dialog</dd> <dt><kbd>S</kbd></dt> <dd>Focus the search field</dd> <dt><kbd>↑</kbd></dt> <dd>Move up in search results</dd> <dt><kbd>↓</kbd></dt> <dd>Move down in search results</dd> <dt><kbd>↹</kbd></dt> <dd>Switch tab</dd> <dt><kbd>⏎</kbd></dt> <dd>Go to active search result</dd> <dt><kbd>+</kbd></dt> <dd>Expand all sections</dd> <dt><kbd>-</kbd></dt> <dd>Collapse all sections</dd> </dl> </div> <div class="infos"> <h2>Search Tricks</h2> <p> Prefix searches with a type followed by a colon (e.g. <code>fn:</code>) to restrict the search to a given type. </p> <p> Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>. </p> <p> Search functions by type signature (e.g. <code>vec -> usize</code> or <code>* -> vec</code>) </p> </div> </div> </aside> <script> window.rootPath = "../../"; window.currentCrate = "std"; </script> <script src="../../main.js"></script> <script defer src="../../search-index.js"></script> </body> </html>