diff options
| author | kennytm <kennytm@gmail.com> | 2019-02-16 00:55:47 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2019-02-16 14:11:28 +0800 |
| commit | f05e6bf7089fa3d5f3b490eb8d9fc89bc044604d (patch) | |
| tree | 256a9a879d98e6aaffb4497c290c8795322c1c2c /src/liballoc/tests/lib.rs | |
| parent | 84e88da4311e4c2dac3789de708ec5232a3deeff (diff) | |
| parent | 317f15304e6091a1f3cc58c52d36df037ef50db0 (diff) | |
| download | rust-f05e6bf7089fa3d5f3b490eb8d9fc89bc044604d.tar.gz rust-f05e6bf7089fa3d5f3b490eb8d9fc89bc044604d.zip | |
Rollup merge of #58074 - scottmcm:stabilize-sort_by_cached_key, r=SimonSapin
Stabilize slice_sort_by_cached_key
I was going to ask on the tracking issue (https://github.com/rust-lang/rust/issues/34447), but decided to just send this and hope for an FCP here. The method was added last March by https://github.com/rust-lang/rust/pull/48639.
Signature: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_by_cached_key
```rust
impl [T] {
pub fn sort_by_cached_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord;
}
```
That's an identical signature to the existing `sort_by_key`, so I think the questions are just naming, implementation, and the usual "do we want this?".
The implementation seems to have proven its use in rustc at least, which many uses: https://github.com/rust-lang/rust/search?l=Rust&q=sort_by_cached_key
(I'm asking because it's exactly what I just needed the other day:
```rust
all_positions.sort_by_cached_key(|&n|
data::CITIES.iter()
.map(|x| *metric_closure.get_edge(n, x.pos).unwrap())
.sum::<usize>()
);
```
since caching that key is a pretty obviously good idea.)
Closes #34447
Diffstat (limited to 'src/liballoc/tests/lib.rs')
| -rw-r--r-- | src/liballoc/tests/lib.rs | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index 2b63ac5c7d2..2361a7db1f7 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -4,7 +4,6 @@ #![feature(exact_size_is_empty)] #![feature(pattern)] #![feature(repeat_generic_slice)] -#![feature(slice_sort_by_cached_key)] #![feature(try_reserve)] #![feature(unboxed_closures)] #![feature(vecdeque_rotate)] |
