Skip to content

Commit 9b35833

Browse files
committed
Document the order of {Vec,VecDeque,String}::retain
It's natural for `retain` to work in order from beginning to end, but this wasn't actually documented to be the case. If we actually promise this, then the caller can do useful things like track the index of each element being tested, as [discussed in the forum][1]. This is now documented for `Vec`, `VecDeque`, and `String`. [1]: https://users.rust-lang.org/t/vec-retain-by-index/27697 `HashMap` and `HashSet` also have `retain`, and the `hashbrown` implementation does happen to use a plain `iter()` order too, but it's not certain that this should always be the case for these types.
1 parent 00859e3 commit 9b35833

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/liballoc/collections/vec_deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,8 +1835,8 @@ impl<T> VecDeque<T> {
18351835
/// Retains only the elements specified by the predicate.
18361836
///
18371837
/// In other words, remove all elements `e` such that `f(&e)` returns false.
1838-
/// This method operates in place and preserves the order of the retained
1839-
/// elements.
1838+
/// This method operates in place, visiting each element exactly once in the
1839+
/// original order, and preserves the order of the retained elements.
18401840
///
18411841
/// # Examples
18421842
///

src/liballoc/string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,8 @@ impl String {
12001200
/// Retains only the characters specified by the predicate.
12011201
///
12021202
/// In other words, remove all characters `c` such that `f(c)` returns `false`.
1203-
/// This method operates in place and preserves the order of the retained
1204-
/// characters.
1203+
/// This method operates in place, visiting each character exactly once in the
1204+
/// original order, and preserves the order of the retained characters.
12051205
///
12061206
/// # Examples
12071207
///

src/liballoc/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,8 @@ impl<T> Vec<T> {
937937
/// Retains only the elements specified by the predicate.
938938
///
939939
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
940-
/// This method operates in place and preserves the order of the retained
941-
/// elements.
940+
/// This method operates in place, visiting each element exactly once in the
941+
/// original order, and preserves the order of the retained elements.
942942
///
943943
/// # Examples
944944
///

0 commit comments

Comments
 (0)