title: FnOnce closures that capture an outer variable
body: <p>I'm trying to write a function that will initialize <code>n</code> threads based on their index:</p>
  <pre><code>use std::iter::FromIterator;
  use std::marker::{Send};
  use std::thread::{JoinHandle, spawn};
  
  // spawn n threads, initialized with their index
  fn nspawn_i&lt;F, T&gt;(n: usize, f: F) -&gt; Vec&lt;JoinHandle&lt;T&gt;&gt;
  where
      F: Fn(usize) -&gt; T,
      F: Send,
      T: Send {
  
      // spawn the i'th thread
      let spawn_i = |mut i: usize| -&gt; JoinHandle&lt;T&gt; {
          spawn(move || f(i))
      };
  
      Vec::from_iter((0..n).map(spawn_i))
  }
  </code></pre>
  <p>However, I get an error</p>
  <pre><code>error[E0525]: expected a closure that implements the `FnMut` trait, but this closure only implements `FnOnce`
    --&gt; src/main.rs:13:19
     |
  13 |     let spawn_i = |mut i: usize| -&gt; JoinHandle&lt;T&gt; {
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this closure implements `FnOnce`, not `FnMut`
  14 |         spawn(move || f(i))
     |               ------- closure is `FnOnce` because it moves the variable `f` out of its environment
  ...
  17 |     Vec::from_iter((0..n).map(spawn_i))
     |                           --- the requirement to implement `FnMut` derives from here
  </code></pre>
  <p>I don't understand why <code>spawn_i</code> is <code>FnOnce</code>, and not <code>FnMut</code>, since the argument is mutable.</p>