summary refs log tree commit diff
path: root/src/liballoc/vec.rs
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2019-04-29 18:32:05 -0700
committerJosh Stone <jistone@redhat.com>2019-04-29 18:32:05 -0700
commit9b3583375dbd45b19b8ce8822b89ff79529354d6 (patch)
tree137494b5e5c41e94a3e33f9fe09bada8cb07541c /src/liballoc/vec.rs
parent00859e3e653973120006aaf3227823062dde1ba7 (diff)
downloadrust-9b3583375dbd45b19b8ce8822b89ff79529354d6.tar.gz
rust-9b3583375dbd45b19b8ce8822b89ff79529354d6.zip
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.
Diffstat (limited to 'src/liballoc/vec.rs')
-rw-r--r--src/liballoc/vec.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index cd62c3e0524..a9bc835010f 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -937,8 +937,8 @@ impl<T> Vec<T> {
     /// Retains only the elements specified by the predicate.
     ///
     /// In other words, remove all elements `e` such that `f(&e)` returns `false`.
-    /// This method operates in place and preserves the order of the retained
-    /// elements.
+    /// This method operates in place, visiting each element exactly once in the
+    /// original order, and preserves the order of the retained elements.
     ///
     /// # Examples
     ///