title: Should I borrow or copy my small data types?
body: <pre><code>struct Vec {
      data: [f32; 3],
  }
  
  impl Vec {
      fn dot(&amp;self, other: &amp;Vec) -&gt; f32 {
          ..
      }
      // vs
      fn dot(self, other: Vec) -&gt; f32 {
          ..
      }
  }
  </code></pre>
  
  <p>I am currently writing a vector math library and I am wondering if I should borrow or copy my vector types.</p>
  
  <p>At the moment I implement <code>Copy</code> for <code>Vec</code> which makes the API a bit nicer because you don't have to write <code>&amp;</code> all the time.</p>
  
  <p>But it requires much more complex constraints, because now all my constraints also need to satisfy <code>Copy</code>.</p>
  
  <p>Which one potentially yields better performance and why?</p>
  
  <p>Which one potentially yields better ergonomics and why?</p>
  
  <p>Edit:</p>
  
  <p>I have created a small <a href="https://github.com/MaikKlein/vector_bench" rel="nofollow">microbenchmark</a></p>
  
  <pre><code>test bref_f32 ... bench:   2,736,055 ns/iter (+/- 364,885)
  test bref_f64 ... bench:   4,872,076 ns/iter (+/- 436,928)
  test copy_f32 ... bench:   2,708,568 ns/iter (+/- 31,162)
  test copy_f64 ... bench:   4,890,014 ns/iter (+/- 553,050)
  </code></pre>
  
  <p>It seems that there is no difference between <code>ref</code> and <code>copy</code> for this example in terms of performance.</p>
  
  <p><code>Copy</code> seems to yield better ergonomics for library users.</p>