title: How to define a function with a generic fixed-length array?
body: <p>Take an operation on arrays, squaring the length for example.</p>
  
  <p>It's useful to have a generic type (such as <code>f32</code>, <code>f64</code>), but you may also want a generic length, but <em>not</em> a dynamic length.</p>
  
  <p>Here is an example of a squared function that takes 2 arguments.</p>
  
  <pre><code>use std::ops::{Add, AddAssign, Sub, Mul};
  
  const CAN_THIS_BE_GENERIC: usize = 2;
  
  fn squared_length&lt;T&gt;(
      a: &amp;[T; CAN_THIS_BE_GENERIC],
      b: &amp;[T; CAN_THIS_BE_GENERIC]
  ) -&gt; T
      where T:
          Copy +
          Add +
          AddAssign +
          Add&lt;Output=T&gt; +
          Sub&lt;Output=T&gt; +
          Mul&lt;Output=T&gt;
  {
      let mut d: T = a[0] - a[0];  // zero :(
      for (elem_a, elem_b) in a.iter().zip(b.iter()) {
          let elem_dim: T = *elem_a - *elem_b;
          d += elem_dim * elem_dim;
      }
      return d;
  }
  
  fn main() {
      println!("Length A! {}", squared_length::&lt;f64&gt;(&amp;[0.5, 3.5], &amp;[10.0, 0.0]));
      println!("Length B! {}", squared_length::&lt;i32&gt;(&amp;[10, -6], &amp;[4, 8]));
      println!("Length C! {}", squared_length::&lt;f32&gt;(&amp;[-3.0, 0.0], &amp;[9.0, 0.0]));
  }
  </code></pre>
  
  <p>Currently the vector length is set at 2.</p>
  
  <p>Is it possible to define generic functions where the size is not dynamic, but generic, the same way types can be generic?</p>