{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreidxtdv6s7qnozpapu2xisnvkw6wduhqxgeyw4xuzx22wpeorb3axi",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mji3szjxbit2"
  },
  "path": "/t/t-sort-by-index-and-t-sort-by-key-and-index/24172#post_7",
  "publishedAt": "2026-04-14T18:23:49.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "https://doc.rust-lang.org/std/primitive.slice.html#method.sort_by_cached_key"
  ],
  "textContent": "Ddystopia:\n\n> but it requires computing intermediate permutation and additional heap space.\n\nNote that https://doc.rust-lang.org/std/primitive.slice.html#method.sort_by_cached_key does that internally, so maybe you could find a way to encode it in that?\n\nThough that _doesn't_ guarantee the _order_ of the calls to the key generator (just that it's at most once per item), so you can't just calculate the index inside the closure.",
  "title": "`<[T]>::sort_by_index` and `<[T]>::sort_by_key_and_index`"
}