title: Rust: make macro accept enum name with variant as argument
body: <p>I want to write a macro, that consumes an enum like this: <code>panic_wrapper!(PanicKind::Alloc, &quot;can't allocate because of: {}&quot;, reason)</code>. I'm having problems with making the macro accept <code>PanicKind::Alloc</code>.</p>
  <p>My current solution works, but I don't think, that it is really nice, because technically I'm deconstructing the Enum name from the variant.</p>
  <pre class="lang-rust prettyprint-override"><code>macro_rules! panic_wrapper {
      ($enum:ident::$variant:ident, $($arg:tt)*) =&gt; {
          println!(&quot;error code={}&quot;, $crate::PanicKind::$variant.code());
          panic!($($arg)*)
      }
  }
  
  #[repr(u32)]
  #[derive(Copy, Clone)]
  enum PanicKind {
      First,
      Second,
      Third,
  }
  
  impl PanicKind {
      fn code(&amp;self) -&gt; u32 {
          *self as u32
      }
  }
  
  fn main() {
      panic_wrapper!(PanicKind::Second, &quot;hello {}&quot;, &quot;there&quot;);
  }
  </code></pre>
  <p>I'm wondering if I can write the macro definition simpler, i.e. don't deconstruct it with <code>$enum:ident::$variant:ident</code>. Also I have to hard code the module path of the enum into the macro with my current solution. Any ideas how I can improve this?</p>