Skip to content

Commit 7b86ba0

Browse files
committed
Add splice to the unstable book.
1 parent c3baa8c commit 7b86ba0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/doc/unstable-book/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
- [slice_rsplit](library-features/slice-rsplit.md)
196196
- [sort_internals](library-features/sort-internals.md)
197197
- [sort_unstable](library-features/sort-unstable.md)
198+
- [splice](library-features/splice.md)
198199
- [step_by](library-features/step-by.md)
199200
- [step_trait](library-features/step-trait.md)
200201
- [str_checked_slicing](library-features/str-checked-slicing.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# `splice`
2+
3+
The tracking issue for this feature is: [#32310]
4+
5+
[#32310]: https://github.com/rust-lang/rust/issues/32310
6+
7+
------------------------
8+
9+
The `splice()` method on `Vec` and `String` allows you to replace a range
10+
of values in a vector or string with another range of values, and returns
11+
the replaced values.
12+
13+
A simple example:
14+
15+
```rust
16+
#![feature(splice)]
17+
let mut s = String::from("α is alpha, β is beta");
18+
let beta_offset = s.find('β').unwrap_or(s.len());
19+
20+
// Replace the range up until the β from the string
21+
let t: String = s.splice(..beta_offset, "Α is capital alpha; ").collect();
22+
assert_eq!(t, "α is alpha, ");
23+
assert_eq!(s, "Α is capital alpha; β is beta");
24+
```

0 commit comments

Comments
 (0)