title: How do I cope with lazy iterators?
body: <p>I'm trying to sort an array with a <code>map()</code> over an iterator.</p>
  
  <pre><code>struct A {
      b: Vec&lt;B&gt;,
  }
  
  #[derive(PartialEq, Eq, PartialOrd, Ord)]
  struct B {
      c: Vec&lt;i32&gt;,
  }
  
  fn main() {
      let mut a = A { b: Vec::new() };
  
      let b = B { c: vec![5, 2, 3] };
      a.b.push(b);
  
      a.b.iter_mut().map(|b| b.c.sort());
  }
  </code></pre>
  
  <p>Gives the warning:</p>
  
  <pre class="lang-none prettyprint-override"><code>warning: unused `std::iter::Map` that must be used
    --&gt; src/main.rs:16:5
     |
  16 |     a.b.iter_mut().map(|b| b.c.sort());
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: #[warn(unused_must_use)] on by default
     = note: iterators are lazy and do nothing unless consumed
  </code></pre>
  
  <p>Which is true, <code>sort()</code> isn't actually called here. This warning is described in the <a href="https://doc.rust-lang.org/1.30.0/book/first-edition/iterators.html" rel="noreferrer">book</a>, but I don't understand why this variation with <code>iter_mut()</code> works fine:</p>
  
  <pre><code>a.b.iter_mut().find(|b| b == b).map(|b| b.c.sort());
  </code></pre>