diff options
author | Matt Ickstadt <mattico8@gmail.com> | 2017-04-08 16:58:47 -0500 |
---|---|---|
committer | Matt Ickstadt <mattico8@gmail.com> | 2017-04-23 21:23:50 -0500 |
commit | 7b86ba0d8de53fece3c5e4a522dbde123f483a7c (patch) | |
tree | 210b2be05ae1e8ca48a9a8b69228f2bf951a16ee | |
parent | c3baa8c0a7c0f90c3630c5eacc8f8783505c90ec (diff) | |
download | rust-7b86ba0d8de53fece3c5e4a522dbde123f483a7c.tar.gz |
Add splice to the unstable book.
-rw-r--r-- | src/doc/unstable-book/src/SUMMARY.md | 1 | ||||
-rw-r--r-- | src/doc/unstable-book/src/library-features/splice.md | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 61347573041..1adc59b84ea 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -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) diff --git a/src/doc/unstable-book/src/library-features/splice.md b/src/doc/unstable-book/src/library-features/splice.md new file mode 100644 index 00000000000..ca7f78a8f79 --- /dev/null +++ b/src/doc/unstable-book/src/library-features/splice.md @@ -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"); +```
\ No newline at end of file |