title: How do I convert an &i32 to f64?
body: <p>I'm trying to solve <a href="https://doc.rust-lang.org/book/ch08-03-hash-maps.html" rel="nofollow noreferrer">an exercise at the end of this chapter in the Rust Book</a>.</p>
  <p>Here is a code sample:</p>
  <pre><code>fn mean(v: &amp;Vec&lt;i32&gt;) -&gt; f64 {
      let mut sum = 0.0;
      let mut count = 0.0;
  
      for val in v {
          sum += &amp;f64::from(val);
          count += 1.0;
      }
  
      sum / count
  }
  
  fn main() {
      let v = vec![1, 2, 3, 4];
  
      println!(&quot;The mean is {}&quot;, mean(&amp;v));
  }
  </code></pre>
  <p>The error is:</p>
  <pre class="lang-none prettyprint-override"><code>error[E0277]: the trait bound `f64: std::convert::From&lt;&amp;i32&gt;` is not satisfied
   --&gt; src/main.rs:6:17
    |
  6 |         sum += &amp;f64::from(val);
    |                 ^^^^^^^^^ the trait `std::convert::From&lt;&amp;i32&gt;` is not implemented for `f64`
    |
    = help: the following implementations were found:
              &lt;f64 as std::convert::From&lt;f32&gt;&gt;
              &lt;f64 as std::convert::From&lt;i16&gt;&gt;
              &lt;f64 as std::convert::From&lt;i32&gt;&gt;
              &lt;f64 as std::convert::From&lt;i8&gt;&gt;
            and 3 others
    = note: required by `std::convert::From::from`
  </code></pre>
  <p>I also tried using the <code>as</code> keyword but it didn't help.</p>