Add splice to the unstable book.
This commit is contained in:
parent
c3baa8c0a7
commit
7b86ba0d8d
@ -195,6 +195,7 @@
|
||||
- [slice_rsplit](library-features/slice-rsplit.md)
|
||||
- [sort_internals](library-features/sort-internals.md)
|
||||
- [sort_unstable](library-features/sort-unstable.md)
|
||||
- [splice](library-features/splice.md)
|
||||
- [step_by](library-features/step-by.md)
|
||||
- [step_trait](library-features/step-trait.md)
|
||||
- [str_checked_slicing](library-features/str-checked-slicing.md)
|
||||
|
24
src/doc/unstable-book/src/library-features/splice.md
Normal file
24
src/doc/unstable-book/src/library-features/splice.md
Normal file
@ -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");
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user