title: How do I match enum values with an integer?
body: <p>I can get an integer value of an enums like this:</p>
  
  <pre><code>enum MyEnum {
      A = 1,
      B,
      C,
  }
  
  let x = MyEnum::C as i32;
  </code></pre>
  
  <p>but I can't seem to do this:</p>
  
  <pre><code>match x {
      MyEnum::A =&gt; {}
      MyEnum::B =&gt; {}
      MyEnum::C =&gt; {}
      _ =&gt; {}
  }
  </code></pre>
  
  <p>How can I either match against the values of the enum or try to convert <code>x</code> back to a <code>MyEnum</code>?</p>
  
  <p>I can see a function like this being useful for enums, but it probably doesn't exist:</p>
  
  <pre><code>impl MyEnum {
      fn from&lt;T&gt;(val: &amp;T) -&gt; Option&lt;MyEnum&gt;;
  }
  </code></pre>