diff options
| author | Josh Stone <jistone@redhat.com> | 2019-05-10 18:01:50 -0700 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2019-05-10 18:01:50 -0700 |
| commit | 0545375ca6822b4b140cd853f368473d69b76227 (patch) | |
| tree | 6be87ecda326a2121b32968c1643039d4877d400 /src/liballoc/string.rs | |
| parent | 9b3583375dbd45b19b8ce8822b89ff79529354d6 (diff) | |
| download | rust-0545375ca6822b4b140cd853f368473d69b76227.tar.gz rust-0545375ca6822b4b140cd853f368473d69b76227.zip | |
Add examples of ordered retain
Diffstat (limited to 'src/liballoc/string.rs')
| -rw-r--r-- | src/liballoc/string.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index aaa38142693..3fdcf95ccaa 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1212,6 +1212,16 @@ impl String { /// /// assert_eq!(s, "foobar"); /// ``` + /// + /// The exact order may be useful for tracking external state, like an index. + /// + /// ``` + /// let mut s = String::from("abcde"); + /// let keep = [false, true, true, false, true]; + /// let mut i = 0; + /// s.retain(|_| (keep[i], i += 1).0); + /// assert_eq!(s, "bce"); + /// ``` #[inline] #[stable(feature = "string_retain", since = "1.26.0")] pub fn retain<F>(&mut self, mut f: F) |
