title: How can I create and append to a Vec<Struct>?
body: <p>The following does not compile:</p>
  
  <pre><code>struct A {
      f: u16,
  }
  
  fn main() {
      let v: Vec&lt;A&gt; = Vec::new();
      let a = A { f: 42 };
      v.append(a);
  }
  </code></pre>
  
  <p>But the compiler message seems to be leading me down the wrong path:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
   --&gt; src/main.rs:8:14
    |
  8 |     v.append(a);
    |              ^ expected mutable reference, found struct `A`
    |
    = note: expected type `&amp;mut std::vec::Vec&lt;A&gt;`
               found type `A` 
  </code></pre>
  
  <p>Editing the code to call <code>append</code> on a reference to <code>a</code>:</p>
  
  <pre><code>v.append(&amp;mut a);
  </code></pre>
  
  <p>Also fails to compile, but with a surprising (to me) message:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
   --&gt; src/main.rs:8:18
    |
  8 |         v.append(&amp;mut a);
    |                  ^^^^^^ expected struct `std::vec::Vec`, found struct `A`
    |
    = note: expected type `&amp;mut std::vec::Vec&lt;A&gt;`
               found type `&amp;mut A`
  </code></pre>
  
  <p>Shouldn't <code>append</code> be looking for an element of the <code>Vec</code>?  It appears to be looking for a <code>Vec</code> itself.  Yet, I believe I'm following the proper creating for a <code>Vec</code> holding elements of type <code>A</code>.  From the Rust book:</p>
  
  <blockquote>
    <p>To create a new, empty vector, we can call the <code>Vec::new</code> function, as
    shown in Listing 8-1.</p>
  
  <pre><code>let v: Vec&lt;i32&gt; = Vec::new();
  </code></pre>
  </blockquote>
  
  <p>(<a href="https://doc.rust-lang.org/book/ch08-01-vectors.html" rel="nofollow noreferrer">https://doc.rust-lang.org/book/ch08-01-vectors.html</a>)</p>
  
  <p>I have successfully used <code>Vec&lt;String&gt;</code> using the same pattern I'm attempting here, but I'm clearly misunderstanding something quite fundamental.</p>