title: Type Casting Option in rust
body: <p>How do I cast optional values in rust?</p>
  <p>This is what I came up with, which does work, but I think there must be a more elegant way.</p>
  <pre class="lang-rust prettyprint-override"><code>pub fn option_t_to_i32_option&lt;T1, T2&gt;(optional_val: Option&lt;T1&gt;) -&gt; Option&lt;T2&gt;
  where
      T2: From&lt;T1&gt;,
  {
      return match optional_val {
          Some(val) =&gt; Some(T2::from(val)),
          None =&gt; None,
      };
  }
  
  </code></pre>