title: How do I cast generic T to f32 if I know that it's possible?
body: <p>I have a generic <code>struct</code> with one field, that can only be <code>i32</code> or <code>f32</code>.</p>
  
  <pre><code>trait MyInt {
      fn blank();
  }
  
  impl MyInt for i32 {
      fn blank() {
          unimplemented!()
      }
  }
  
  impl MyInt for f32 {
      fn blank() {
          unimplemented!()
      }
  }
  
  struct MyStruct&lt;T&gt; where T: MyInt {
      field: T
  }
  
  impl&lt;T&gt; MyStruct&lt;T&gt; where T: MyInt {
      fn new(var: T) -&gt; MyStruct&lt;T&gt; {
          MyStruct {
              field: var
          }
      }
  }
  </code></pre>
  
  <p>Now I want to add a method which returns field value <code>as f32</code>, whether it's <code>i32</code> or <code>f32</code>. I know that this cast should always be possible since field types are limited to two mentioned above, but how do I go about it? Apparently <code>as</code> only works on primitive types and I tried going the <code>From</code> route, but I am doing something wrong, this doesn't work.</p>
  
  <pre><code>fn to_f32(&amp;self) -&gt; f32 where T: From&lt;i32&gt; {
          f32::from(self.field);
  }
  </code></pre>