title: Building an enum inside a macro
body: <p>Is it possible to build an enum inside a Rust macro using fields that are defined as macro parameters? I've tried this:</p>
  
  <pre><code>macro_rules! build {
      ($($case:ty),*) =&gt; { enum Test { $($case),* } };
  }
  
  fn main() {
      build!{ Foo(i32), Bar(i32, i32) };
  }
  </code></pre>
  
  <p>But it fails with <code>error: expected ident, found 'Foo(i32)'</code></p>
  
  <p>Note that if the fields are defined inside the enum, there is no problem:</p>
  
  <pre><code>macro_rules! build {
      ($($case:ty),*) =&gt; { enum Test { Foo(i32), Bar(i32, i32) } };
  }
  
  fn main() {
      build!{ Foo(i32), Bar(i32, i32) };
  }
  </code></pre>
  
  <p>It also works if my macro only accepts simple fields:</p>
  
  <pre><code>macro_rules! build {
      ($($case:ident),*) =&gt; { enum Test { $($case),* } };
  }
  
  fn main() {
      build!{ Foo, Bar };
  }
  </code></pre>
  
  <p>But I've been unable to get it to work in the general case.</p>