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.
Rollup merge of rust-lang#40434 - mattico:splice-update, r=alexcrichton
Implement Vec::splice and String::splice (RFC 1432) RFC: rust-lang/rfcs#1432, tracking issue: rust-lang#32310 A rebase of rust-lang#32355 with a few more tests. Let me know if you have any ideas for more tests. cc @SimonSapin
- Loading branch information
Showing
8 changed files
with
449 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# `splice` | ||
|
||
The tracking issue for this feature is: [#32310] | ||
|
||
[#32310]: https://github.com/rust-lang/rust/issues/32310 | ||
|
||
------------------------ | ||
|
||
The `splice()` method on `Vec` and `String` allows you to replace a range | ||
of values in a vector or string with another range of values, and returns | ||
the replaced values. | ||
|
||
A simple example: | ||
|
||
```rust | ||
#![feature(splice)] | ||
let mut s = String::from("α is alpha, β is beta"); | ||
let beta_offset = s.find('β').unwrap_or(s.len()); | ||
|
||
// Replace the range up until the β from the string | ||
let t: String = s.splice(..beta_offset, "Α is capital alpha; ").collect(); | ||
assert_eq!(t, "α is alpha, "); | ||
assert_eq!(s, "Α is capital alpha; β is beta"); | ||
``` |
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
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
Oops, something went wrong.