forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#43500 - murarth:string-retain, r=alexcrichton
Add method `String::retain` Behaves like `Vec::retain`, accepting a predicate `FnMut(char) -> bool` and reducing the string to only characters for which the predicate returns `true`.
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/doc/unstable-book/src/library-features/string-retain.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# `string_retain` | ||
|
||
The tracking issue for this feature is: [#43874] | ||
|
||
[#43874]: https://github.com/rust-lang/rust/issues/43874 | ||
|
||
------------------------ | ||
|
||
Retains only the characters specified by the predicate. | ||
|
||
In other words, remove all characters `c` such that `f(c)` returns `false`. | ||
This method operates in place and preserves the order of the retained | ||
characters. | ||
|
||
```rust | ||
#![feature(string_retain)] | ||
|
||
let mut s = String::from("f_o_ob_ar"); | ||
|
||
s.retain(|c| c != '_'); | ||
|
||
assert_eq!(s, "foobar"); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters