Rollup merge of #92071 - ajtribick:patch-1, r=the8472

Update example code for Vec::splice to change the length

The current example for `Vec::splice` illustrates the replacement of a section of length 2 with a new section of length 2. This isn't a particularly interesting case for splice, and makes it look a bit like a shorthand for the kind of manipulations that could be done with a mutable slice.

In order to provide a stronger example, this updates the example to use different lengths for the source and destination regions, and uses a slice from the middle of the vector to illustrate that this does not necessarily have to be at the beginning or the end.

Resolves #92067
This commit is contained in:
Matthias Krüger 2021-12-19 10:45:54 +01:00 committed by GitHub
commit 690d6b0958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2683,11 +2683,11 @@ fn extend_desugared<I: Iterator<Item = T>>(&mut self, mut iterator: I) {
/// # Examples
///
/// ```
/// let mut v = vec![1, 2, 3];
/// let new = [7, 8];
/// let u: Vec<_> = v.splice(..2, new).collect();
/// assert_eq!(v, &[7, 8, 3]);
/// assert_eq!(u, &[1, 2]);
/// let mut v = vec![1, 2, 3, 4];
/// let new = [7, 8, 9];
/// let u: Vec<_> = v.splice(1..3, new).collect();
/// assert_eq!(v, &[1, 7, 8, 9, 4]);
/// assert_eq!(u, &[2, 3]);
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]