Why does HashMap have iter_mut() but HashSet doesn't?
<p>What is the design rationale for supplying an <code>iter_mut</code> function for <a href="https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.iter_mut" rel="noreferrer"><code>HashMap</code></a> but not <a href="http://doc.rust-lang.org/std/collections/struct.HashSet.html" rel="noreferrer"><code>HashSet</code></a> in Rust? </p>

<p>Would it be a faux pas to roll one's own (assuming that can even be done)?</p>

<p>Having one could alleviate situations that give rise to</p>

<blockquote>
  <p>previous borrow of <code>X</code> occurs here; the immutable borrow prevents 
  subsequent moves or mutable borrows of <code>X</code> until the borrow ends</p>
</blockquote>

<h1>Example</h1>

<p><a href="https://play.rust-lang.org/?gist=be2ab19dda2d479dc715&amp;version=stable" rel="noreferrer">An extremely convoluted example (Gist)</a> that does not show-case why the parameter passing is the way that it is. Has a short comment explaining the pain-point:</p>

<pre><code>use std::collections::HashSet;

fn derp(v: i32, unprocessed: &amp;mut HashSet&lt;i32&gt;) {
    if unprocessed.contains(&amp;v) {

        // Pretend that v has been processed
        unprocessed.remove(&amp;v);
    }   
}

fn herp(v: i32) {
    let mut unprocessed: HashSet&lt;i32&gt; = HashSet::new();
    unprocessed.insert(v);

    // I need to iterate over the unprocessed values
    while let Some(u) = unprocessed.iter().next() {

        // And them pass them mutably to another function
        // as I will process the values inside derp and
        // remove them from the set.
        //
        // This is an extremely convoluted example but
        // I need for derp to be a separate function
        // as I will employ recursion there, as it is
        // much more succinct than an iterative version.
        derp(*u, &amp;mut unprocessed);
    }   
}

fn main() {
    println!("Hello, world!");
    herp(10);
}
</code></pre>

<p>The statement</p>

<pre><code>while let Some(u) = unprocessed.iter().next() {
</code></pre>

<p>is an immutable borrow, hence</p>

<pre><code>derp(*u, &amp;mut unprocessed);
</code></pre>

<p>is impossible as unprocessed cannot be borrowed mutably. The immutable borrow does not end until the end of the while-loop.</p>

<p>I have tried to use <a href="http://blog.ezyang.com/2013/12/two-bugs-in-the-borrow-checker-every-rust-developer-should-know-about/" rel="noreferrer">this as reference</a> and essentially ended up with trying to fool the borrow checker through various permutations of assignments, enclosing braces, but due to the coupling of the intended expressions the problem remains.</p>