Skip to content

Commit 3eb87db

Browse files
authored
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.
1 parent ca8078d commit 3eb87db

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

library/alloc/src/slice.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ impl<T> [T] {
374374
/// During sorting, the key function is called only once per element.
375375
///
376376
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*m* \* *n* + *n* \* log(*n*))
377-
/// worst-case, where the key function is *O*(*m*).
377+
/// worst-case, where the key function is *O*(*m*). If the slice requires sorting,
378+
/// the key function is called on all elements of the slice in the original order.
378379
///
379380
/// For simple key functions (e.g., functions that are property accesses or
380381
/// basic operations), [`sort_by_key`](slice::sort_by_key) is likely to be

0 commit comments

Comments
 (0)