Skip to content

Commit 690d6b0

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#92067
2 parents 4dbe966 + 574bc67 commit 690d6b0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,11 +2683,11 @@ impl<T, A: Allocator> Vec<T, A> {
26832683
/// # Examples
26842684
///
26852685
/// ```
2686-
/// let mut v = vec![1, 2, 3];
2687-
/// let new = [7, 8];
2688-
/// let u: Vec<_> = v.splice(..2, new).collect();
2689-
/// assert_eq!(v, &[7, 8, 3]);
2690-
/// assert_eq!(u, &[1, 2]);
2686+
/// let mut v = vec![1, 2, 3, 4];
2687+
/// let new = [7, 8, 9];
2688+
/// let u: Vec<_> = v.splice(1..3, new).collect();
2689+
/// assert_eq!(v, &[1, 7, 8, 9, 4]);
2690+
/// assert_eq!(u, &[2, 3]);
26912691
/// ```
26922692
#[cfg(not(no_global_oom_handling))]
26932693
#[inline]

0 commit comments

Comments
 (0)