title: How to iterate over several option vectors in Rust?
body: <p>I have several option vectors' references over <code>Rc</code> pointers to trait objects and I'd like to iterate over all their items.</p>
  
  <p>Basically, declaration of those vectors looks like this:</p>
  
  <pre class="lang-rust prettyprint-override"><code>let vec_0: Option&lt;&amp;Vec&lt;Rc&lt;TraitObject&gt;&gt;&gt; = ...;
  let vec_1: Option&lt;&amp;Vec&lt;Rc&lt;TraitObject&gt;&gt;&gt; = ...;
  ...
  let vec_n: Option&lt;&amp;Vec&lt;Rc&lt;TraitObject&gt;&gt;&gt; = ...;
  </code></pre>
  
  <p>I tried using <code>chain()</code> method like this:</p>
  
  <pre class="lang-rust prettyprint-override"><code>let it = vec_o.unwrap_or(&amp;vec![]).iter()
      .chain(vec_1.unwrap_or(&amp;vec![]))
      ...
      .chain(vec_n.unwrap_or(&amp;vec![]));
  
  for el in it {
      ...
  }
  </code></pre>
  
  <p>But there was a problem with this code, as those empty vectors are temporary objects that'd be deleted by the time the iterator is used.</p>
  
  <p>Right now I've done it the straigtforward way:</p>
  
  <pre class="lang-rust prettyprint-override"><code>let mut vector = vec![];
  if let Some(vc) = vec_0 {
      vector.extend(vc.iter())
  }
  
  if let Some(vc) = vec_1 {
      vector.extend(vc.iter())
  }
  
  ...
  
  if let Some(vc) = vec_n {
      vector.extend(vc.iter())
  }
  
  for el in vector {
      ...
  }
  </code></pre>
  
  <p>This one looks cumbersome and not that convenient for reading.</p>
  
  <p>Is there any way to iterate through all elements of <code>vec_0</code>, <code>vec_1</code>, etc. easier? I am a newbie in Rust, and it seems to me that there must be solution with <code>chain()</code> method.</p>
  
  <p>Any help will be appreciated =)</p>