title: Sort a slice based on keys in another slice without allocating
body: <p>This is not a duplicate of <a href="https://stackoverflow.com/questions/32564455/how-can-i-co-sort-two-vecs-based-on-the-values-in-one-of-the-vecs">How can I co-sort two Vecs based on the values in one of the Vecs?</a>, because the <code>permutation</code> crate's implementation allocates.</p>
  <p>How can I sort a slice based on the contents of another slice without allocating?</p>
  <pre class="lang-rust prettyprint-override"><code>slice1 = [
      AAA, BBB, CCC, DDD
  ]
  
  slice2 = [
      12, -3, 6, 17
  ]
  
  </code></pre>
  <p>Result:</p>
  <pre class="lang-rust prettyprint-override"><code>[BBB, CCC, AAA, DDD]
  </code></pre>
  <p>Both <code>slice1</code> and <code>slice2</code> are not too large (integers, at most about 1 KiB, usually much smaller), but this sort could be done very often. It is not required to preserve <code>slice2</code>, so it could be implemented by sorting <code>slice2</code> and performing the same operations on <code>slice1</code> at the same time, but any sorting implementation I made would perform poorer than the standard library implementation.</p>