Skip to content

Commit 14e0869

Browse files
improve Vec::extends_from_within docs
1 parent 8a09420 commit 14e0869

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

library/alloc/src/vec/mod.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -2392,26 +2392,31 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
23922392
self.spec_extend(other.iter())
23932393
}
23942394

2395-
/// Copies elements from `src` range to the end of the vector.
2395+
/// Appends elements specified by the `src` parameter to the end of the vector.
2396+
/// The `src` parameter is of type [`RangeBounds`], which means that
2397+
/// it can be used to specify a range of elements in the vector.
2398+
///
2399+
/// [`RangeBounds`]: ../../std/ops/trait.RangeBounds.html
23962400
///
23972401
/// # Panics
23982402
///
2399-
/// Panics if the starting point is greater than the end point or if
2400-
/// the end point is greater than the length of the vector.
2403+
/// Panics if the starting index is greater than the end index.
2404+
/// Panics if the end index is greater than the length of the vector.
24012405
///
24022406
/// # Examples
24032407
///
24042408
/// ```
2405-
/// let mut vec = vec![0, 1, 2, 3, 4];
2406-
///
2407-
/// vec.extend_from_within(2..);
2408-
/// assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4]);
2409+
/// let mut characters1 = vec!['a', 'b', 'c', 'd', 'e'];
2410+
/// characters1.extend_from_within(2..);
2411+
/// assert_eq!(characters1, ['a', 'b', 'c', 'd', 'e', 'c', 'd', 'e']);
24092412
///
2410-
/// vec.extend_from_within(..2);
2411-
/// assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1]);
2413+
/// let mut characters2 = vec!['a', 'b', 'c', 'd', 'e'];
2414+
/// characters2.extend_from_within(..2);
2415+
/// assert_eq!(characters2, ['a', 'b', 'c', 'd', 'e', 'a', 'b']);
24122416
///
2413-
/// vec.extend_from_within(4..8);
2414-
/// assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1, 4, 2, 3, 4]);
2417+
/// let mut characters3 = vec!['a', 'b', 'c', 'd', 'e'];
2418+
/// characters3.extend_from_within(1..3);
2419+
/// assert_eq!(characters3, ['a', 'b', 'c', 'd', 'e', 'b', 'c']);
24152420
/// ```
24162421
#[cfg(not(no_global_oom_handling))]
24172422
#[stable(feature = "vec_extend_from_within", since = "1.53.0")]

0 commit comments

Comments
 (0)