From 14e0869bf3de34af8cbb90abb723bfe6c897afe3 Mon Sep 17 00:00:00 2001 From: Fabian Hintringer Date: Wed, 23 Nov 2022 14:29:37 +0100 Subject: [PATCH] improve Vec::extends_from_within docs --- library/alloc/src/vec/mod.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index e147af2ce39c..4925a7a73e53 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2392,26 +2392,31 @@ impl Vec { self.spec_extend(other.iter()) } - /// Copies elements from `src` range to the end of the vector. + /// Appends elements specified by the `src` parameter to the end of the vector. + /// The `src` parameter is of type [`RangeBounds`], which means that + /// it can be used to specify a range of elements in the vector. + /// + /// [`RangeBounds`]: ../../std/ops/trait.RangeBounds.html /// /// # Panics /// - /// Panics if the starting point is greater than the end point or if - /// the end point is greater than the length of the vector. + /// Panics if the starting index is greater than the end index. + /// Panics if the end index is greater than the length of the vector. /// /// # Examples /// /// ``` - /// let mut vec = vec![0, 1, 2, 3, 4]; - /// - /// vec.extend_from_within(2..); - /// assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4]); + /// let mut characters1 = vec!['a', 'b', 'c', 'd', 'e']; + /// characters1.extend_from_within(2..); + /// assert_eq!(characters1, ['a', 'b', 'c', 'd', 'e', 'c', 'd', 'e']); /// - /// vec.extend_from_within(..2); - /// assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1]); + /// let mut characters2 = vec!['a', 'b', 'c', 'd', 'e']; + /// characters2.extend_from_within(..2); + /// assert_eq!(characters2, ['a', 'b', 'c', 'd', 'e', 'a', 'b']); /// - /// vec.extend_from_within(4..8); - /// assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1, 4, 2, 3, 4]); + /// let mut characters3 = vec!['a', 'b', 'c', 'd', 'e']; + /// characters3.extend_from_within(1..3); + /// assert_eq!(characters3, ['a', 'b', 'c', 'd', 'e', 'b', 'c']); /// ``` #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_extend_from_within", since = "1.53.0")]