{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreifbif6expxlgut5uxaeeuysqzf6mu7v5glkh7pe2l4crkkgu3o7xe",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mjilmvlc2w22"
  },
  "path": "/t/t-sort-by-index-and-t-sort-by-key-and-index/24172#post_6",
  "publishedAt": "2026-04-14T15:59:11.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "To avoid internal allocation you could oblige caller to supply a scratch array of `[usize; N]`.\n\n**EDIT:** Concretely, suppose we added _this_ function to slices\n\n\n    /// for 0 <= i < self.len() move item i to position permutation[i]\n    /// panics if self.len() != permutation.len()\n    /// (if possible make that a type constraint)\n    /// or if permutation is not actually a permutation of 0..self.len()\n    pub fn permute(&mut self, permutation: &[usize])\n\n\nthen I think the existing `<[usize]>::sort_(unstable_)by_key` could do the rest of the job?",
  "title": "`<[T]>::sort_by_index` and `<[T]>::sort_by_key_and_index`"
}