title: How to pass an array of objects implementing a certain trait to a function?
body: <p>To learn Rust syntax, I've decided to implement a function sorting a passed-in array:</p>
  
  <pre><code>fn sort(array) {
      // actual sorting
  }
  </code></pre>
  
  <p>In <a href="https://stackoverflow.com/questions/24831828/how-do-i-pass-an-array-to-a-function-in-rust-and-change-its-content">this question</a> I found out how to pass an array and change its content, but besides this the array must consist of types that can be compared. I've found the <a href="https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html" rel="nofollow noreferrer"><code>std::cmp::PartialOrd</code></a> trait and figured out that the elements of an array need to implement it.</p>
  
  <p>By connecting this knowledge with the paragraph about <a href="https://doc.rust-lang.org/book/first-edition/trait-objects.html#dynamic-dispatch" rel="nofollow noreferrer">dynamic dispatch</a> in the Rust book I've built something like this:</p>
  
  <pre><code>use std::cmp;
  
  fn sort(arr: &amp;mut [&amp;std::cmp::PartialOrd]) {
      // actual sorting
  }
  </code></pre>
  
  <p>This doesn't compile:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0393]: the type parameter `Rhs` must be explicitly specified
   --&gt; src/lib.rs:3:21
    |
  3 | fn sort(arr: &amp;mut [&amp;std::cmp::PartialOrd]) {
    |                     ^^^^^^^^^^^^^^^^^^^^ missing reference to `Rhs`
    |
    = note: because of the default `Self` reference, type parameters must be specified on object types
  </code></pre>
  
  <p>Is there a correct syntax to achieve passing an array of objects implementing a certain trait to a function?</p>