rust/library/alloc
Matthias Krüger 2a4381d8ea
Rollup merge of #89621 - digama0:patch-2, r=yaahc
doc: guarantee call order for sort_by_cached_key

`slice::sort_by_cached_key` takes a caching function `f: impl FnMut(&T) -> K`, which means that the order that calls to the caching function are made is user-visible. This adds a clause to the documentation to promise the current behavior, which is that `f` is called on all elements of the slice from left to right, unless the slice has len < 2 in which case `f` is not called.

For example, this can be used to ensure that the following code is a correct way to involve the index of the element in the sort key:
```rust
let mut index = 0;
slice.sort_by_cached_key(|x| (my_key(index, x), index += 1).0);
```
2022-01-19 10:42:13 +01:00
..
benches update vec::retain benchmarks 2021-12-04 16:20:35 +01:00
src Rollup merge of #89621 - digama0:patch-2, r=yaahc 2022-01-19 10:42:13 +01:00
tests Stabilize vec_spare_capacity 2022-01-17 21:07:02 +00:00
Cargo.toml Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00