Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > fdedb3cf2140df9b6d419a2338ab1caa > files > 48

rust-doc-1.25.0-1.mga6.x86_64.rpm

<!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">&#9776;</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&lt;Vec&lt;T&gt;&gt;</a><a href="#impl-From%3CBinaryHeap%3CT%3E%3E">From&lt;BinaryHeap&lt;T&gt;&gt;</a><a href="#impl-FromIterator%3CT%3E">FromIterator&lt;T&gt;</a><a href="#impl-IntoIterator">IntoIterator</a><a href="#impl-Extend%3CT%3E">Extend&lt;T&gt;</a><a href="#impl-Extend%3C%26%27a%20T%3E">Extend&lt;&amp;&#39;a T&gt;</a><a href="#impl-Placer%3CT%3E">Placer&lt;T&gt;</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'>&#x2212;</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&lt;T&gt; { /* 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&lt;i32&gt;` 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&#39;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&#39;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">&amp;</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">&amp;</span><span class="ident">heap</span> {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</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&lt;T:&nbsp;<a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>&gt; <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;</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>() -&gt; <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;</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) -&gt; <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;</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>&lt;'a, T&gt;</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>&lt;'a, T&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, T&gt; <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>&lt;'a, T&gt;</span><span class="where fmt-newline">    type <a href='../../core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &amp;'a T;</span></code></div></div><span id='iter.v' class='invisible'><code>pub fn <a href='#method.iter' class='fnname'>iter</a>(&amp;self) -&gt; <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a>&lt;T&gt;</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">&quot;{}&quot;</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>(&amp;self) -&gt; <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;T&gt;</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">&amp;</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>(&amp;mut self) -&gt; <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../alloc/binary_heap/struct.PeekMut.html" title="struct alloc::binary_heap::PeekMut">PeekMut</a>&lt;T&gt;&gt;</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">&amp;</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>(&amp;self) -&gt; 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">&gt;=</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>(&amp;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">&gt;=</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>(&amp;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">&gt;=</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>(&amp;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">&lt;</span><span class="ident">i32</span><span class="op">&gt;</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">&gt;=</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>(&amp;mut self) -&gt; <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;T&gt;</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>(&amp;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">&amp;</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) -&gt; <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;T&gt;</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">&quot;{}&quot;</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) -&gt; <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;T&gt;</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>(&amp;self) -&gt; 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>(&amp;self) -&gt; 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>&lt;'a, T&gt;</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>&lt;'a, T&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, T:&nbsp;'a&gt; <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>&lt;'a, T&gt;</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>(&amp;mut self) -&gt; <a class="struct" href="../../alloc/binary_heap/struct.Drain.html" title="struct alloc::binary_heap::Drain">Drain</a>&lt;T&gt;</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">&quot;{}&quot;</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>(&amp;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>(&amp;mut self, other: &amp;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">&amp;</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&lt;T:&nbsp;<a class="trait" href="../../core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt; <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>&lt;T&gt;</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>(&amp;self) -&gt; 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>(&amp;mut self, source: &amp;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&lt;T:&nbsp;<a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>&gt; <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>&lt;T&gt;</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>() -&gt; <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;</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&lt;T&gt;</code>.</p>
</div></div><h3 id='impl-Debug' class='impl'><span class='in-band'><code>impl&lt;T:&nbsp;<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>&gt; <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>&lt;T&gt;</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>(&amp;self, f: &amp;mut <a class="struct" href="../../alloc/fmt/struct.Formatter.html" title="struct alloc::fmt::Formatter">Formatter</a>) -&gt; <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&lt;T:&nbsp;<a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>&gt; <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;T&gt;&gt; for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;</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>&lt;T&gt;) -&gt; <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;</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&lt;T&gt; <a class="trait" href="../../core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;&gt; for <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;T&gt;</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>&lt;T&gt;) -&gt; <a class="struct" href="../../alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;T&gt;</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&lt;T:&nbsp;<a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>&gt; <a class="trait" href="../../core/iter/traits/trait.FromIterator.html" title="trait core::iter::traits::FromIterator">FromIterator</a>&lt;T&gt; for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;</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>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = T&gt;&gt;(iter: I) -&gt; <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;</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&lt;T:&nbsp;<a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>&gt; <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>&lt;T&gt;</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>&lt;T&gt;</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>&lt;T&gt;</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>&lt;T&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;T&gt; <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>&lt;T&gt;</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) -&gt; <a class="struct" href="../../alloc/binary_heap/struct.IntoIter.html" title="struct alloc::binary_heap::IntoIter">IntoIter</a>&lt;T&gt;</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 &amp;i32</span>
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">x</span>);
}</pre>
</div></div><h3 id='impl-IntoIterator-1' class='impl'><span class='in-band'><code>impl&lt;'a, T&gt; <a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a> for &amp;'a <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,&nbsp;</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> = &amp;'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>&lt;'a, T&gt;</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>&lt;'a, T&gt;</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>&lt;'a, T&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, T&gt; <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>&lt;'a, T&gt;</span><span class="where fmt-newline">    type <a href='../../core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &amp;'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) -&gt; <a class="struct" href="../../alloc/binary_heap/struct.Iter.html" title="struct alloc::binary_heap::Iter">Iter</a>&lt;'a, T&gt;</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&lt;T:&nbsp;<a class="trait" href="../../core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>&gt; <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a>&lt;T&gt; for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;</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>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = T&gt;&gt;(&amp;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&lt;'a, T:&nbsp;'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>&gt; <a class="trait" href="../../core/iter/traits/trait.Extend.html" title="trait core::iter::traits::Extend">Extend</a>&lt;&amp;'a T&gt; for <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt;</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>&lt;I:&nbsp;<a class="trait" href="../../core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = &amp;'a T&gt;&gt;(&amp;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&lt;'a, T:&nbsp;'a&gt; <a class="trait" href="../../core/ops/place/trait.Placer.html" title="trait core::ops::place::Placer">Placer</a>&lt;T&gt; for &amp;'a mut <a class="struct" href="../../alloc/binary_heap/struct.BinaryHeap.html" title="struct alloc::binary_heap::BinaryHeap">BinaryHeap</a>&lt;T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;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>,&nbsp;</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>&lt;'a, T&gt;</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) -&gt; 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>&#9166;</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>