diff options
| author | bors <bors@rust-lang.org> | 2025-01-14 08:45:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-01-14 08:45:47 +0000 |
| commit | a48e7b00570baaaba9d32d783d5702c06afd104d (patch) | |
| tree | 109eb26a2829d9582bb3490b4611bff9ef755f96 /library | |
| parent | e491caec14c2ec293c0f9bf2b208ba7e91336dd1 (diff) | |
| parent | 4cadb5d513348fa2eee2e1ef1d50eca5dc9030bc (diff) | |
| download | rust-a48e7b00570baaaba9d32d783d5702c06afd104d.tar.gz rust-a48e7b00570baaaba9d32d783d5702c06afd104d.zip | |
Auto merge of #135473 - matthiaskrgr:rollup-ksnst4l, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #135381 (Add an example for `Vec::splice` inserting elements without removing) - #135451 (Remove code duplication when hashing query result and interning node) - #135464 (fix ICE with references to infinite structs in consts) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 3a706d5f36b..cd2afd7a473 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -3587,7 +3587,7 @@ impl<T, A: Allocator> Vec<T, A> { /// with the given `replace_with` iterator and yields the removed items. /// `replace_with` does not need to be the same length as `range`. /// - /// `range` is removed even if the iterator is not consumed until the end. + /// `range` is removed even if the `Splice` iterator is not consumed before it is dropped. /// /// It is unspecified how many elements are removed from the vector /// if the `Splice` value is leaked. @@ -3613,8 +3613,18 @@ impl<T, A: Allocator> Vec<T, A> { /// 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]); + /// assert_eq!(v, [1, 7, 8, 9, 4]); + /// assert_eq!(u, [2, 3]); + /// ``` + /// + /// Using `splice` to insert new items into a vector efficiently at a specific position + /// indicated by an empty range: + /// + /// ``` + /// let mut v = vec![1, 5]; + /// let new = [2, 3, 4]; + /// v.splice(1..1, new); + /// assert_eq!(v, [1, 2, 3, 4, 5]); /// ``` #[cfg(not(no_global_oom_handling))] #[inline] |
