Skip to content

Commit d0c4a78

Browse files
committed
Improve documentation
1 parent efdd9e8 commit d0c4a78

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,26 +3025,28 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
30253025
self.spec_extend(other.iter())
30263026
}
30273027

3028-
/// Copies elements from `src` range to the end of the vector.
3028+
/// Copies elements from one part of the vector to the end.
3029+
/// `src` is the range that the elements will be copied from.
30293030
///
30303031
/// # Panics
30313032
///
3032-
/// Panics if the starting point is greater than the end point or if
3033-
/// the end point is greater than the length of the vector.
3033+
/// Panics if the starting index is greater than the end index.
3034+
/// Panics if the end index is greater than the length of the vector.
30343035
///
30353036
/// # Examples
30363037
///
30373038
/// ```
3038-
/// let mut vec = vec![0, 1, 2, 3, 4];
3039-
///
3040-
/// vec.extend_from_within(2..);
3041-
/// assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4]);
3042-
///
3043-
/// vec.extend_from_within(..2);
3044-
/// assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1]);
3045-
///
3046-
/// vec.extend_from_within(4..8);
3047-
/// assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1, 4, 2, 3, 4]);
3039+
/// let mut characters1 = vec!['a', 'b', 'c', 'd', 'e'];
3040+
/// characters1.extend_from_within(2..);
3041+
/// assert_eq!(characters1, ['a', 'b', 'c', 'd', 'e', 'c', 'd', 'e']);
3042+
3043+
/// let mut characters2 = vec!['a', 'b', 'c', 'd', 'e'];
3044+
/// characters2.extend_from_within(..2);
3045+
/// assert_eq!(characters2, ['a', 'b', 'c', 'd', 'e', 'a', 'b']);
3046+
3047+
/// let mut characters3 = vec!['a', 'b', 'c', 'd', 'e'];
3048+
/// characters2.extend_from_within(1..3);
3049+
/// assert_eq!(characters3, ['a', 'b', 'c', 'd', 'e', 'b', 'c']);
30483050
/// ```
30493051
#[cfg(not(no_global_oom_handling))]
30503052
#[stable(feature = "vec_extend_from_within", since = "1.53.0")]

0 commit comments

Comments
 (0)