title: Can macros expand array/vector into multiple indexed arguments?
body: <p>Is it possible to write a macro that expands an expression into multiple indexed arguments, which can be passed to a function or another macro?</p>
  
  <p>See this simple self contained example.<br>The aim is to have <code>unpack3</code> expand <code>v</code> into <code>v[0], v[1], v[2]</code>.</p>
  
  <pre><code>macro_rules! elem {
      ($val:expr, $($var:expr), *) =&gt; {
          $($val == $var) || *
      }
  }
  
  // attempt to expand an array.
  macro_rules! unpack3 {
      ($v:expr) =&gt; {
          $v[0], $v[1], $v[2]
      }
  }
  
  fn main() {
      let a = 2;
      let vars = [0, 1, 3];
      // works!
      if elem!(a, vars[0], vars[1], vars[2]) {
          println!("Found!");
      }
      // fails!
      if elem!(a, unpack3!(vars)) {
          println!("Found!");
      }
  }
  </code></pre>
  
  <p>The second example fails, is it possible to make this work?</p>
  
  <p>Possible solutions could include:</p>
  
  <ul>
  <li>Changing use of macro grammar.</li>
  <li>Using tuples, then expanding into arguments after.</li>
  <li>Re-arranging the expressions to workaround macro constraints.</li>
  </ul>
  
  <hr>
  
  <p>Note, this may be related to <a href="https://stackoverflow.com/questions/31195529/escaping-commas-in-macro-output">Escaping commas in macro output</a> but don't think its a duplicate.</p>