Rollup merge of #44640 - budziq:stabilize_splice, r=dtolnay
Stabilized vec_splice and modified splice tracking issue This stabilizes the vec_splice (Vec part of splice RFC) Fixes #32310.
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
# `splice`
|
# `splice`
|
||||||
|
|
||||||
The tracking issue for this feature is: [#32310]
|
The tracking issue for this feature is: [#44643]
|
||||||
|
|
||||||
[#32310]: https://github.com/rust-lang/rust/issues/32310
|
[#44643]: https://github.com/rust-lang/rust/issues/44643
|
||||||
|
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
The `splice()` method on `Vec` and `String` allows you to replace a range
|
The `splice()` method on `String` allows you to replace a range
|
||||||
of values in a vector or string with another range of values, and returns
|
of values in a string with another range of values.
|
||||||
the replaced values.
|
|
||||||
|
|
||||||
A simple example:
|
A simple example:
|
||||||
|
|
||||||
|
|||||||
@@ -1451,7 +1451,7 @@ impl String {
|
|||||||
/// s.splice(..beta_offset, "Α is capital alpha; ");
|
/// s.splice(..beta_offset, "Α is capital alpha; ");
|
||||||
/// assert_eq!(s, "Α is capital alpha; β is beta");
|
/// assert_eq!(s, "Α is capital alpha; β is beta");
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
|
#[unstable(feature = "splice", reason = "recently added", issue = "44643")]
|
||||||
pub fn splice<R>(&mut self, range: R, replace_with: &str)
|
pub fn splice<R>(&mut self, range: R, replace_with: &str)
|
||||||
where R: RangeArgument<usize>
|
where R: RangeArgument<usize>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1943,7 +1943,6 @@ impl<T> Vec<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(splice)]
|
|
||||||
/// let mut v = vec![1, 2, 3];
|
/// let mut v = vec![1, 2, 3];
|
||||||
/// let new = [7, 8];
|
/// let new = [7, 8];
|
||||||
/// let u: Vec<_> = v.splice(..2, new.iter().cloned()).collect();
|
/// let u: Vec<_> = v.splice(..2, new.iter().cloned()).collect();
|
||||||
@@ -1951,7 +1950,7 @@ impl<T> Vec<T> {
|
|||||||
/// assert_eq!(u, &[1, 2]);
|
/// assert_eq!(u, &[1, 2]);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
|
#[stable(feature = "vec_splice", since = "1.22.0")]
|
||||||
pub fn splice<R, I>(&mut self, range: R, replace_with: I) -> Splice<I::IntoIter>
|
pub fn splice<R, I>(&mut self, range: R, replace_with: I) -> Splice<I::IntoIter>
|
||||||
where R: RangeArgument<usize>, I: IntoIterator<Item=T>
|
where R: RangeArgument<usize>, I: IntoIterator<Item=T>
|
||||||
{
|
{
|
||||||
@@ -2554,13 +2553,13 @@ impl<'a, T> InPlace<T> for PlaceBack<'a, T> {
|
|||||||
/// [`splice()`]: struct.Vec.html#method.splice
|
/// [`splice()`]: struct.Vec.html#method.splice
|
||||||
/// [`Vec`]: struct.Vec.html
|
/// [`Vec`]: struct.Vec.html
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
|
#[stable(feature = "vec_splice", since = "1.22.0")]
|
||||||
pub struct Splice<'a, I: Iterator + 'a> {
|
pub struct Splice<'a, I: Iterator + 'a> {
|
||||||
drain: Drain<'a, I::Item>,
|
drain: Drain<'a, I::Item>,
|
||||||
replace_with: I,
|
replace_with: I,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
|
#[stable(feature = "vec_splice", since = "1.22.0")]
|
||||||
impl<'a, I: Iterator> Iterator for Splice<'a, I> {
|
impl<'a, I: Iterator> Iterator for Splice<'a, I> {
|
||||||
type Item = I::Item;
|
type Item = I::Item;
|
||||||
|
|
||||||
@@ -2573,18 +2572,18 @@ impl<'a, I: Iterator> Iterator for Splice<'a, I> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
|
#[stable(feature = "vec_splice", since = "1.22.0")]
|
||||||
impl<'a, I: Iterator> DoubleEndedIterator for Splice<'a, I> {
|
impl<'a, I: Iterator> DoubleEndedIterator for Splice<'a, I> {
|
||||||
fn next_back(&mut self) -> Option<Self::Item> {
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
self.drain.next_back()
|
self.drain.next_back()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
|
#[stable(feature = "vec_splice", since = "1.22.0")]
|
||||||
impl<'a, I: Iterator> ExactSizeIterator for Splice<'a, I> {}
|
impl<'a, I: Iterator> ExactSizeIterator for Splice<'a, I> {}
|
||||||
|
|
||||||
|
|
||||||
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
|
#[stable(feature = "vec_splice", since = "1.22.0")]
|
||||||
impl<'a, I: Iterator> Drop for Splice<'a, I> {
|
impl<'a, I: Iterator> Drop for Splice<'a, I> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// exhaust drain first
|
// exhaust drain first
|
||||||
|
|||||||
Reference in New Issue
Block a user