File tree 2 files changed +25
-0
lines changed
src/doc/unstable-book/src
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 195
195
- [ slice_rsplit] ( library-features/slice-rsplit.md )
196
196
- [ sort_internals] ( library-features/sort-internals.md )
197
197
- [ sort_unstable] ( library-features/sort-unstable.md )
198
+ - [ splice] ( library-features/splice.md )
198
199
- [ step_by] ( library-features/step-by.md )
199
200
- [ step_trait] ( library-features/step-trait.md )
200
201
- [ str_checked_slicing] ( library-features/str-checked-slicing.md )
Original file line number Diff line number Diff line change
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
+ ```
You can’t perform that action at this time.
0 commit comments