<!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 `BinaryHeap` struct in crate `alloc`."> <meta name="keywords" content="rust, rustlang, rust-lang, BinaryHeap"> <title>alloc::binary_heap::BinaryHeap - 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 struct"> <!--[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='../../alloc/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a> <p class='location'>Struct BinaryHeap</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.new">new</a><a href="#method.with_capacity">with_capacity</a><a href="#method.iter">iter</a><a href="#method.peek">peek</a><a href="#method.peek_mut">peek_mut</a><a href="#method.capacity">capacity</a><a href="#method.reserve_exact">reserve_exact</a><a href="#method.reserve">reserve</a><a href="#method.shrink_to_fit">shrink_to_fit</a><a href="#method.pop">pop</a><a href="#method.push">push</a><a href="#method.into_vec">into_vec</a><a href="#method.into_sorted_vec">into_sorted_vec</a><a href="#method.len">len</a><a href="#method.is_empty">is_empty</a><a href="#method.drain">drain</a><a href="#method.clear">clear</a><a href="#method.append">append</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Clone">Clone</a><a href="#impl-Default">Default</a><a href="#impl-Debug">Debug</a><a href="#impl-From%3CVec%3CT%3E%3E">From<Vec<T>></a><a href="#impl-From%3CBinaryHeap%3CT%3E%3E">From<BinaryHeap<T>></a><a href="#impl-FromIterator%3CT%3E">FromIterator<T></a><a href="#impl-IntoIterator">IntoIterator</a><a href="#impl-Extend%3CT%3E">Extend<T></a><a href="#impl-Extend%3C%26%27a%20T%3E">Extend<&'a T></a><a href="#impl-Placer%3CT%3E">Placer<T></a></div></div><p class='location'><a href='../index.html'>alloc</a>::<wbr><a href='index.html'>binary_heap</a></p><script>window.sidebarCurrent = {name: 'BinaryHeap', ty: 'struct', 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'>Struct <a href='../index.html'>alloc</a>::<wbr><a href='index.html'>binary_heap</a>::<wbr><a class="struct" href=''>BinaryHeap</a></span><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='../../src/alloc/binary_heap.rs.html#221-223' title='goto source code'>[src]</a></span></h1> <pre class='rust struct'>pub struct BinaryHeap<T> { /* fields omitted */ }</pre><div class='docblock'><p>A priority queue implemented with a binary heap.</p> <p>This will be a max-heap.</p> <p>It is a logic error for an item to be modified in such a way that the item's ordering relative to any other item, as determined by the <code>Ord</code> trait, changes while it is in the heap. This is normally only possible through <code>Cell</code>, <code>RefCell</code>, global state, I/O, or unsafe code.</p> <h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="comment">// Type inference lets us omit an explicit type signature (which</span> <span class="comment">// would be `BinaryHeap<i32>` in this example).</span> <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">new</span>(); <span class="comment">// We can use peek to look at the next item in the heap. In this case,</span> <span class="comment">// there's no items in there yet so we get None.</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">peek</span>(), <span class="prelude-val">None</span>); <span class="comment">// Let's add some scores...</span> <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">1</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">5</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">2</span>); <span class="comment">// Now peek shows the most important item in the heap.</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">peek</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">5</span>)); <span class="comment">// We can check the length of a heap.</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">len</span>(), <span class="number">3</span>); <span class="comment">// We can iterate over the items in the heap, although they are returned in</span> <span class="comment">// a random order.</span> <span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="kw-2">&</span><span class="ident">heap</span> { <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>); } <span class="comment">// If we instead pop these scores, they should come back in order.</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">pop</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">heap</span>.<span class="ident">pop</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">heap</span>.<span class="ident">pop</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">heap</span>.<span class="ident">pop</span>(), <span class="prelude-val">None</span>); <span class="comment">// We can clear the heap of any remaining items.</span> <span class="ident">heap</span>.<span class="ident">clear</span>(); <span class="comment">// The heap should now be empty.</span> <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">is_empty</span>())</pre> </div> <h2 id='methods' class='small-section-header'> Methods<a href='#methods' class='anchor'></a> </h2> <h3 id='impl' class='impl'><span class='in-band'><code>impl<T: <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>> <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code><a href='#impl' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#309-834' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><code>pub fn <a href='#method.new' class='fnname'>new</a>() -> <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#322-324' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates an empty <code>BinaryHeap</code> as a max-heap.</p> <h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">new</span>(); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">4</span>);</pre> </div><h4 id='method.with_capacity' class="method"><span id='with_capacity.v' class='invisible'><code>pub fn <a href='#method.with_capacity' class='fnname'>with_capacity</a>(capacity: usize) -> <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#341-343' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates an empty <code>BinaryHeap</code> with a specific capacity. This preallocates enough memory for <code>capacity</code> elements, so that the <code>BinaryHeap</code> does not have to be reallocated until it contains at least that many values.</p> <h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">4</span>);</pre> </div><h4 id='method.iter' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a><'a, T></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a><'a, T></h3><code class="content"><span class="where fmt-newline">impl<'a, T> <a class="trait" href="../../core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a><'a, T></span><span class="where fmt-newline"> type <a href='../../core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &'a T;</span></code></div></div><span id='iter.v' class='invisible'><code>pub fn <a href='#method.iter' class='fnname'>iter</a>(&self) -> <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a><T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#362-364' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Returns an iterator visiting all values in the underlying vector, in arbitrary order.</p> <h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">from</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="comment">// Print 1, 2, 3, 4 in arbitrary order</span> <span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">heap</span>.<span class="ident">iter</span>() { <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>); }</pre> </div><h4 id='method.peek' class="method"><span id='peek.v' class='invisible'><code>pub fn <a href='#method.peek' class='fnname'>peek</a>(&self) -> <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a><&T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#384-386' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Returns the greatest item in the binary heap, or <code>None</code> if it is empty.</p> <h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">new</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">peek</span>(), <span class="prelude-val">None</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">1</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">5</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">2</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">peek</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">5</span>)); </pre> </div><h4 id='method.peek_mut' class="method"><span id='peek_mut.v' class='invisible'><code>pub fn <a href='#method.peek_mut' class='fnname'>peek_mut</a>(&mut self) -> <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../../alloc/binary_heap/struct.PeekMut.html" title="struct alloc::binary_heap::PeekMut">PeekMut</a><T>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.12.0'>1.12.0</div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#413-422' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Returns a mutable reference to the greatest item in the binary heap, or <code>None</code> if it is empty.</p> <p>Note: If the <code>PeekMut</code> value is leaked, the heap may be in an inconsistent state.</p> <h1 id="examples-5" class="section-header"><a href="#examples-5">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">new</span>(); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">peek_mut</span>().<span class="ident">is_none</span>()); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">1</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">5</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">2</span>); { <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">val</span> <span class="op">=</span> <span class="ident">heap</span>.<span class="ident">peek_mut</span>().<span class="ident">unwrap</span>(); <span class="kw-2">*</span><span class="ident">val</span> <span class="op">=</span> <span class="number">0</span>; } <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">peek</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">2</span>));</pre> </div><h4 id='method.capacity' class="method"><span id='capacity.v' class='invisible'><code>pub fn <a href='#method.capacity' class='fnname'>capacity</a>(&self) -> usize</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#437-439' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Returns the number of elements the binary heap can hold without reallocating.</p> <h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">with_capacity</span>(<span class="number">100</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">100</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">4</span>);</pre> </div><h4 id='method.reserve_exact' class="method"><span id='reserve_exact.v' class='invisible'><code>pub fn <a href='#method.reserve_exact' class='fnname'>reserve_exact</a>(&mut self, additional: usize)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#466-468' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Reserves the minimum capacity for exactly <code>additional</code> more elements to be inserted in the given <code>BinaryHeap</code>. Does nothing if the capacity is already sufficient.</p> <p>Note that the allocator may give the collection more space than it requests. Therefore capacity can not be relied upon to be precisely minimal. Prefer <a href="#method.reserve"><code>reserve</code></a> if future insertions are expected.</p> <h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1> <p>Panics if the new capacity overflows <code>usize</code>.</p> <h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">new</span>(); <span class="ident">heap</span>.<span class="ident">reserve_exact</span>(<span class="number">100</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">100</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">4</span>);</pre> </div><h4 id='method.reserve' class="method"><span id='reserve.v' class='invisible'><code>pub fn <a href='#method.reserve' class='fnname'>reserve</a>(&mut self, additional: usize)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#489-491' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Reserves capacity for at least <code>additional</code> more elements to be inserted in the <code>BinaryHeap</code>. The collection may reserve more space to avoid frequent reallocations.</p> <h1 id="panics-1" class="section-header"><a href="#panics-1">Panics</a></h1> <p>Panics if the new capacity overflows <code>usize</code>.</p> <h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">new</span>(); <span class="ident">heap</span>.<span class="ident">reserve</span>(<span class="number">100</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">100</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">4</span>);</pre> </div><h4 id='method.shrink_to_fit' class="method"><span id='shrink_to_fit.v' class='invisible'><code>pub fn <a href='#method.shrink_to_fit' class='fnname'>shrink_to_fit</a>(&mut self)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#508-510' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Discards as much additional capacity as possible.</p> <h1 id="examples-9" class="section-header"><a href="#examples-9">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span>: <span class="ident">BinaryHeap</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">with_capacity</span>(<span class="number">100</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">capacity</span>() <span class="op">>=</span> <span class="number">100</span>); <span class="ident">heap</span>.<span class="ident">shrink_to_fit</span>(); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">capacity</span>() <span class="op">==</span> <span class="number">0</span>);</pre> </div><h4 id='method.pop' class="method"><span id='pop.v' class='invisible'><code>pub fn <a href='#method.pop' class='fnname'>pop</a>(&mut self) -> <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a><T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#528-536' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Removes the greatest item from the binary heap and returns it, or <code>None</code> if it is empty.</p> <h1 id="examples-10" class="section-header"><a href="#examples-10">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">from</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">3</span>]); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">pop</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">heap</span>.<span class="ident">pop</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">heap</span>.<span class="ident">pop</span>(), <span class="prelude-val">None</span>);</pre> </div><h4 id='method.push' class="method"><span id='push.v' class='invisible'><code>pub fn <a href='#method.push' class='fnname'>push</a>(&mut self, item: T)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#555-559' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Pushes an item onto the binary heap.</p> <h1 id="examples-11" class="section-header"><a href="#examples-11">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">new</span>(); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">3</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">5</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">1</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">len</span>(), <span class="number">3</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">peek</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">5</span>));</pre> </div><h4 id='method.into_vec' class="method"><span id='into_vec.v' class='invisible'><code>pub fn <a href='#method.into_vec' class='fnname'>into_vec</a>(self) -> <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#579-581' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Consumes the <code>BinaryHeap</code> and returns the underlying vector in arbitrary order.</p> <h1 id="examples-12" class="section-header"><a href="#examples-12">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">from</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="number">6</span>, <span class="number">7</span>]); <span class="kw">let</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">heap</span>.<span class="ident">into_vec</span>(); <span class="comment">// Will print in some order</span> <span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">vec</span> { <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>); }</pre> </div><h4 id='method.into_sorted_vec' class="method"><span id='into_sorted_vec.v' class='invisible'><code>pub fn <a href='#method.into_sorted_vec' class='fnname'>into_sorted_vec</a>(self) -> <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#601-609' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Consumes the <code>BinaryHeap</code> and returns a vector in sorted (ascending) order.</p> <h1 id="examples-13" class="section-header"><a href="#examples-13">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">from</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">7</span>]); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">6</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">3</span>); <span class="kw">let</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">heap</span>.<span class="ident">into_sorted_vec</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</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="number">6</span>, <span class="number">7</span>]);</pre> </div><h4 id='method.len' class="method"><span id='len.v' class='invisible'><code>pub fn <a href='#method.len' class='fnname'>len</a>(&self) -> usize</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#700-702' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Returns the length of the binary heap.</p> <h1 id="examples-14" class="section-header"><a href="#examples-14">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">from</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">3</span>]); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">len</span>(), <span class="number">2</span>);</pre> </div><h4 id='method.is_empty' class="method"><span id='is_empty.v' class='invisible'><code>pub fn <a href='#method.is_empty' class='fnname'>is_empty</a>(&self) -> bool</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#723-725' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Checks if the binary heap is empty.</p> <h1 id="examples-15" class="section-header"><a href="#examples-15">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">new</span>(); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">is_empty</span>()); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">3</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">5</span>); <span class="ident">heap</span>.<span class="ident">push</span>(<span class="number">1</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">heap</span>.<span class="ident">is_empty</span>());</pre> </div><h4 id='method.drain' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../alloc/binary_heap/struct.Drain.html" title="struct alloc::binary_heap::Drain">Drain</a><'a, T></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../alloc/binary_heap/struct.Drain.html" title="struct alloc::binary_heap::Drain">Drain</a><'a, T></h3><code class="content"><span class="where fmt-newline">impl<'a, T: 'a> <a class="trait" href="../../core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../../alloc/binary_heap/struct.Drain.html" title="struct alloc::binary_heap::Drain">Drain</a><'a, T></span><span class="where fmt-newline"> type <a href='../../core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = T;</span></code></div></div><span id='drain.v' class='invisible'><code>pub fn <a href='#method.drain' class='fnname'>drain</a>(&mut self) -> <a class="struct" href="../../alloc/binary_heap/struct.Drain.html" title="struct alloc::binary_heap::Drain">Drain</a><T></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.6.0'>1.6.0</div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#749-751' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Clears the binary heap, returning an iterator over the removed elements.</p> <p>The elements are removed in arbitrary order.</p> <h1 id="examples-16" class="section-header"><a href="#examples-16">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">from</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">3</span>]); <span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">heap</span>.<span class="ident">is_empty</span>()); <span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">heap</span>.<span class="ident">drain</span>() { <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>); } <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">is_empty</span>());</pre> </div><h4 id='method.clear' class="method"><span id='clear.v' class='invisible'><code>pub fn <a href='#method.clear' class='fnname'>clear</a>(&mut self)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#770-772' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Drops all items from the binary heap.</p> <h1 id="examples-17" class="section-header"><a href="#examples-17">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">from</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">3</span>]); <span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">heap</span>.<span class="ident">is_empty</span>()); <span class="ident">heap</span>.<span class="ident">clear</span>(); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">heap</span>.<span class="ident">is_empty</span>());</pre> </div><h4 id='method.append' class="method"><span id='append.v' class='invisible'><code>pub fn <a href='#method.append' class='fnname'>append</a>(&mut self, other: &mut Self)</code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.11.0'>1.11.0</div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#803-833' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Moves all the elements of <code>other</code> into <code>self</code>, leaving <code>other</code> empty.</p> <h1 id="examples-18" class="section-header"><a href="#examples-18">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <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="op">-</span><span class="number">10</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">3</span>]; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">a</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">from</span>(<span class="ident">v</span>); <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="op">-</span><span class="number">20</span>, <span class="number">5</span>, <span class="number">43</span>]; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">b</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">from</span>(<span class="ident">v</span>); <span class="ident">a</span>.<span class="ident">append</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">b</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">into_sorted_vec</span>(), [<span class="op">-</span><span class="number">20</span>, <span class="op">-</span><span class="number">10</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">43</span>]); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">b</span>.<span class="ident">is_empty</span>());</pre> </div></div> <h2 id='implementations' class='small-section-header'> Trait Implementations<a href='#implementations' class='anchor'></a> </h2> <h3 id='impl-Clone' class='impl'><span class='in-band'><code>impl<T: <a class="trait" href="../../core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> <a class="trait" href="../../core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code><a href='#impl-Clone' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#283-291' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><code>fn <a href='../../core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&self) -> Self</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#284-286' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Returns a copy of the value. <a href="../../core/clone/trait.Clone.html#tymethod.clone">Read more</a></p> </div><h4 id='method.clone_from' class="method"><span id='clone_from.v' class='invisible'><code>fn <a href='../../core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, source: &Self)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#288-290' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="../../core/clone/trait.Clone.html#method.clone_from">Read more</a></p> </div></div><h3 id='impl-Default' class='impl'><span class='in-band'><code>impl<T: <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>> <a class="trait" href="../../core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code><a href='#impl-Default' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#294-300' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.default' class="method"><span id='default.v' class='invisible'><code>fn <a href='../../core/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -> <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#297-299' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates an empty <code>BinaryHeap<T></code>.</p> </div></div><h3 id='impl-Debug' class='impl'><span class='in-band'><code>impl<T: <a class="trait" href="../../alloc/fmt/trait.Debug.html" title="trait alloc::fmt::Debug">Debug</a> + <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>> <a class="trait" href="../../alloc/fmt/trait.Debug.html" title="trait alloc::fmt::Debug">Debug</a> for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code><a href='#impl-Debug' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#303-307' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='../../alloc/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="../../alloc/fmt/struct.Formatter.html" title="struct alloc::fmt::Formatter">Formatter</a>) -> <a class="type" href="../../alloc/fmt/type.Result.html" title="type alloc::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#304-306' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Formats the value using the given formatter. <a href="../../alloc/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p> </div></div><h3 id='impl-From%3CVec%3CT%3E%3E' class='impl'><span class='in-band'><code>impl<T: <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>> <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T>> for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code><a href='#impl-From%3CVec%3CT%3E%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1072-1078' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.from' class="method"><span id='from.v' class='invisible'><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(vec: <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T>) -> <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1073-1077' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-From%3CBinaryHeap%3CT%3E%3E' class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T>> for <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T></code><a href='#impl-From%3CBinaryHeap%3CT%3E%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1081-1085' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.from-1' class="method"><span id='from.v-1' class='invisible'><code>fn <a href='../../core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(heap: <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T>) -> <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1082-1084' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-FromIterator%3CT%3E' class='impl'><span class='in-band'><code>impl<T: <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>> <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a><T> for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code><a href='#impl-FromIterator%3CT%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1088-1092' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.from_iter' class="method"><span id='from_iter.v' class='invisible'><code>fn <a href='../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = T>>(iter: I) -> <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1089-1091' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates a value from an iterator. <a href="../../core/iter/traits/trait.FromIterator.html#tymethod.from_iter">Read more</a></p> </div></div><h3 id='impl-IntoIterator' class='impl'><span class='in-band'><code>impl<T: <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>> <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a> for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code><a href='#impl-IntoIterator' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1095-1120' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='associatedtype.Item' class="type"><span id='Item.t' class='invisible'><code>type <a href='../../core/iter/traits/trait.IntoIterator.html#associatedtype.Item' class="type">Item</a> = T</code></span></h4> <div class='docblock'><p>The type of the elements being iterated over.</p> </div><h4 id='associatedtype.IntoIter' class="type"><span id='IntoIter.t' class='invisible'><code>type <a href='../../core/iter/traits/trait.IntoIterator.html#associatedtype.IntoIter' class="type">IntoIter</a> = <a class="struct" href="../../alloc/binary_heap/struct.IntoIter.html" title="struct alloc::binary_heap::IntoIter">IntoIter</a><T></code></span></h4> <div class='docblock'><p>Which kind of iterator are we turning this into?</p> </div><h4 id='method.into_iter' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../alloc/binary_heap/struct.IntoIter.html" title="struct alloc::binary_heap::IntoIter">IntoIter</a><T></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../alloc/binary_heap/struct.IntoIter.html" title="struct alloc::binary_heap::IntoIter">IntoIter</a><T></h3><code class="content"><span class="where fmt-newline">impl<T> <a class="trait" href="../../core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../../alloc/binary_heap/struct.IntoIter.html" title="struct alloc::binary_heap::IntoIter">IntoIter</a><T></span><span class="where fmt-newline"> type <a href='../../core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = T;</span></code></div></div><span id='into_iter.v' class='invisible'><code>fn <a href='../../core/iter/traits/trait.IntoIterator.html#tymethod.into_iter' class='fnname'>into_iter</a>(self) -> <a class="struct" href="../../alloc/binary_heap/struct.IntoIter.html" title="struct alloc::binary_heap::IntoIter">IntoIter</a><T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1117-1119' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates a consuming iterator, that is, one that moves each value out of the binary heap in arbitrary order. The binary heap cannot be used after calling this.</p> <h1 id="examples-19" class="section-header"><a href="#examples-19">Examples</a></h1> <p>Basic usage:</p> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BinaryHeap</span>; <span class="kw">let</span> <span class="ident">heap</span> <span class="op">=</span> <span class="ident">BinaryHeap</span>::<span class="ident">from</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="comment">// Print 1, 2, 3, 4 in arbitrary order</span> <span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">heap</span>.<span class="ident">into_iter</span>() { <span class="comment">// x has type i32, not &i32</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>); }</pre> </div></div><h3 id='impl-IntoIterator-1' class='impl'><span class='in-band'><code>impl<'a, T> <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a> for &'a <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></code><a href='#impl-IntoIterator-1' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1123-1132' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='associatedtype.Item-1' class="type"><span id='Item.t-1' class='invisible'><code>type <a href='../../core/iter/traits/trait.IntoIterator.html#associatedtype.Item' class="type">Item</a> = &'a T</code></span></h4> <div class='docblock'><p>The type of the elements being iterated over.</p> </div><h4 id='associatedtype.IntoIter-1' class="type"><span id='IntoIter.t-1' class='invisible'><code>type <a href='../../core/iter/traits/trait.IntoIterator.html#associatedtype.IntoIter' class="type">IntoIter</a> = <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a><'a, T></code></span></h4> <div class='docblock'><p>Which kind of iterator are we turning this into?</p> </div><h4 id='method.into_iter-1' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a><'a, T></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a><'a, T></h3><code class="content"><span class="where fmt-newline">impl<'a, T> <a class="trait" href="../../core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a><'a, T></span><span class="where fmt-newline"> type <a href='../../core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &'a T;</span></code></div></div><span id='into_iter.v-1' class='invisible'><code>fn <a href='../../core/iter/traits/trait.IntoIterator.html#tymethod.into_iter' class='fnname'>into_iter</a>(self) -> <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a><'a, T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1129-1131' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates an iterator from a value. <a href="../../core/iter/traits/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p> </div></div><h3 id='impl-Extend%3CT%3E' class='impl'><span class='in-band'><code>impl<T: <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>> <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a><T> for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code><a href='#impl-Extend%3CT%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1135-1140' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.extend' class="method"><span id='extend.v' class='invisible'><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = T>>(&mut self, iter: I)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1137-1139' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Extends a collection with the contents of an iterator. <a href="../../core/iter/traits/trait.Extend.html#tymethod.extend">Read more</a></p> </div></div><h3 id='impl-Extend%3C%26%27a%20T%3E' class='impl'><span class='in-band'><code>impl<'a, T: 'a + <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> + <a class="trait" href="../../core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a>> <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a><&'a T> for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T></code><a href='#impl-Extend%3C%26%27a%20T%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1168-1172' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.extend-1' class="method"><span id='extend.v-1' class='invisible'><code>fn <a href='../../core/iter/traits/trait.Extend.html#tymethod.extend' class='fnname'>extend</a><I: <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a><Item = &'a T>>(&mut self, iter: I)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1169-1171' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Extends a collection with the contents of an iterator. <a href="../../core/iter/traits/trait.Extend.html#tymethod.extend">Read more</a></p> </div></div><h3 id='impl-Placer%3CT%3E' class='impl'><span class='in-band'><code>impl<'a, T: 'a> <a class="trait" href="../../core/ops/place/trait.Placer.html" title="trait core::ops::place::Placer">Placer</a><T> for &'a mut <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></code><a href='#impl-Placer%3CT%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1197-1209' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='associatedtype.Place' class="type"><span id='Place.t' class='invisible'><code>type <a href='../../core/ops/place/trait.Placer.html#associatedtype.Place' class="type">Place</a> = <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeapPlace.html" title="struct alloc::binary_heap::BinaryHeapPlace">BinaryHeapPlace</a><'a, T></code></span></h4> <div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API. (<code>placement_new_protocol </code><a href="https://github.com/rust-lang/rust/issues/27779">#27779</a>)</div></div><div class='docblock'><p><code>Place</code> is the intermediate agent guarding the uninitialized state for <code>Data</code>. <a href="../../core/ops/place/trait.Placer.html#associatedtype.Place">Read more</a></p> </div><h4 id='method.make_place' class="method"><span id='make_place.v' class='invisible'><code>fn <a href='../../core/ops/place/trait.Placer.html#tymethod.make_place' class='fnname'>make_place</a>(self) -> Self::<a class="type" href="../../core/ops/place/trait.Placer.html#associatedtype.Place" title="type core::ops::place::Placer::Place">Place</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/binary_heap.rs.html#1201-1208' title='goto source code'>[src]</a></span></h4> <div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API. (<code>placement_new_protocol </code><a href="https://github.com/rust-lang/rust/issues/27779">#27779</a>)</div></div><div class='docblock'><p>Creates a fresh place from <code>self</code>.</p> </div></div></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 = "alloc"; </script> <script src="../../main.js"></script> <script defer src="../../search-index.js"></script> </body> </html>