title: Iterating over a vector of mutable references to trait objects
body: <p>I have a <code>struct</code> that holds mutable references to trait objects:</p>
  
  <pre><code>trait Task {
      fn do_it(&amp;mut self);
  }
  
  struct Worker&lt;'a&gt; {
      tasks: Vec&lt;&amp;'a mut Task&gt;,
  }
  </code></pre>
  
  <p>In a method of <code>Worker</code>, I want to iterate over the tasks and call their <code>do_it</code>:</p>
  
  <pre><code>impl&lt;'a&gt; Worker&lt;'a&gt; {
      pub fn work(&amp;mut self) {
          for task in self.tasks.iter() {
              self.work_one(*task);
          }
      }
  
      fn work_one(&amp;self, task: &amp;mut Task) {
          task.do_it();
      }
  }
  </code></pre>
  
  <p>Sadly, the borrow checker does not let me do it:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0389]: cannot borrow data mutably in a `&amp;` reference
    --&gt; src/main.rs:12:27
     |
  12 |             self.work_one(*task);
     |                           ^^^^^ assignment into an immutable reference
  </code></pre>
  
  <p>I cannot make <code>Worker</code> generic because I want it to hold tasks of many types. I also need tasks to be mutable. How do I do it in Rust?</p>