title: Method `mul` has an incompatible type for trait
body: <p>I'm creating a simple matrix struct in Rust and I'm trying to implement some basic operator methods:</p>
  
  <pre><code>use std::ops::Mul;
  
  struct Matrix {
      cols: i32,
      rows: i32,
      data: Vec&lt;f32&gt;,
  }
  
  impl Matrix {
      fn new(cols: i32, rows: i32, data: Vec&lt;f32&gt;) -&gt; Matrix {
          Matrix {
              cols: cols,
              rows: rows,
              data: data,
          }
      }
  }
  
  impl Mul&lt;f32&gt; for Matrix {
      type Output = Matrix;
  
      fn mul(&amp;self, m: f32) -&gt; Matrix {
          let mut new_data = Vec::with_capacity(self.cols * self.rows);
  
          for i in 0..self.cols * self.rows {
              new_data[i] = self.data[i] * m;
          }
  
          return Matrix {
              cols: *self.cols,
              rows: *self.rows,
              data: new_data,
          };
      }
  }
  
  fn main() {}
  </code></pre>
  
  <p>I'm still familiarizing myself with Rust and systems programming and I'm sure the error is pretty obvious. The compiler tells me:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0053]: method `mul` has an incompatible type for trait
    --&gt; src/main.rs:22:5
     |
  22 |     fn mul(&amp;self, m: f32) -&gt; Matrix {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Matrix`, found &amp;Matrix
     |
     = note: expected type `fn(Matrix, f32) -&gt; Matrix`
                found type `fn(&amp;Matrix, f32) -&gt; Matrix`
  </code></pre>
  
  <p>It's referring to the contents of the for loop (I believe). I've tried playing around with a few other things but I can't get my head around it.</p>