{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreierzbdviqavpdahvxffkm55ahjufquilha73wwv4s3i6n4kvi6t2u",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mjp3vaj4n6a2"
},
"path": "/t/t-sort-by-index-and-t-sort-by-key-and-index/24172#post_19",
"publishedAt": "2026-04-17T12:10:22.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "I did think of that, but I suspect the T-libs folks won't want the stdlib doing that.\n\nBut: this is an expensive check no matter what -- intrinsically has to scan the whole array -- and you might want to use the same permutation multiple times, so maybe a wrapper class something like\n\n\n struct Permutation<N: usize>([usize; N]);\n\n impl Permutation {\n /// Checks that `indices` define a permutation\n fn from_indices(indices: [usize; N])\n -> Result<Self, NotAPermutationError>;\n\n /// Uses self to permute the first N elements of `s`\n /// it is an error if s.len() < N\n fn permute<T: Sized>(&self, s: &mut [T]) -> Result<(), TooSmallError>;\n }\n\n\n(API sketch only, type annotations for illustration only and may be bogus)",
"title": "`<[T]>::sort_by_index` and `<[T]>::sort_by_key_and_index`"
}