title: Zip iterables with Optional and Non Optional parameter in macro
body: <p>For the testing part of my lexer, I came up with a simple macro that let met define the expected token type (enum) and the token literal (string):</p>
  <pre class="lang-rust prettyprint-override"><code>macro_rules! token_test {
      ($($ttype:ident: $literal:literal)*) =&gt; {
          {
              vec!($($ttype,)*).iter().zip(vec!($($literal,)*).iter())
          }
      }
  }
  </code></pre>
  <p>and then I can use it like this:</p>
  <pre class="lang-rust prettyprint-override"><code>for (ttype, literal) in token_test! {
      Let: &quot;let&quot; Identifier: &quot;five&quot; Assign: &quot;=&quot; Int: &quot;5&quot; Semicolon: &quot;;&quot;
  } {
      //...
  }
  </code></pre>
  <p>However, this is a little bit verbose and <strong>we don't need to specify the literal for most of the token since I have another macro that transforms an enum variant into a string (eg: Let -&gt; &quot;let&quot;)</strong>.</p>
  <p>So what I hope to do is something like:</p>
  <pre class="lang-rust prettyprint-override"><code>for (ttype, literal) in token_test! {
      Let Identifier: &quot;five&quot; Assign Int: &quot;5&quot; Semicolon
  } {
      //...
  }
  </code></pre>
  <p>And if I understood properly, I can use optional parameters to match either <code>TYPE: LITERAL</code> or <code>TYPE</code>. Maybe something like:</p>
  <pre class="lang-rust prettyprint-override"><code>macro_rules! token_test {
      ($($ttype:ident$(: $literal:literal)?)*) =&gt; {
          {
              //...
          }
      }
  }
  </code></pre>
  <p>So then my question is is there a way to build <code>Vector</code> out of this?</p>
  <p>To be more clear:</p>
  <ul>
  <li>In the case of no literal passed, it should add the string representation of my enum (eg: Let -&gt; &quot;let&quot;)</li>
  <li>In the case of literal passed, it should add the literal directly</li>
  </ul>