Skip to content

Commit c18461d

Browse files
improve Vec::extends_from_within docs
1 parent 3f2b2ee commit c18461d

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

library/alloc/src/vec/mod.rs

+38-15
Original file line numberDiff line numberDiff line change
@@ -2392,26 +2392,49 @@ 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
2403-
///
2404-
/// ```
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-
///
2410-
/// vec.extend_from_within(..2);
2411-
/// assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1]);
2412-
///
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]);
2407+
///
2408+
/// With numbers:
2409+
///
2410+
/// ```
2411+
/// let mut numbers1 = vec![0, 1, 2, 3, 4];
2412+
/// numbers1.extend_from_within(2..);
2413+
/// assert_eq!(numbers1, [0, 1, 2, 3, 4, 2, 3, 4]);
2414+
///
2415+
/// let mut numbers2 = vec![0, 1, 2, 3, 4];
2416+
/// numbers2.extend_from_within(..2);
2417+
/// assert_eq!(numbers2, [0, 1, 2, 3, 4, 0, 1]);
2418+
///
2419+
/// let mut numbers3 = vec![0, 1, 2, 3, 4];
2420+
/// numbers3.extend_from_within(1..3);
2421+
/// assert_eq!(numbers3, [0, 1, 2, 3, 4, 1, 2]);
2422+
/// ```
2423+
///
2424+
/// With characters:
2425+
///
2426+
/// ```
2427+
/// let mut characters1 = vec!['a', 'b', 'c', 'd', 'e'];
2428+
/// characters1.extend_from_within(2..);
2429+
/// assert_eq!(characters1, ['a', 'b', 'c', 'd', 'e', 'c', 'd', 'e']);
2430+
///
2431+
/// let mut characters2 = vec!['a', 'b', 'c', 'd', 'e'];
2432+
/// characters2.extend_from_within(..2);
2433+
/// assert_eq!(characters2, ['a', 'b', 'c', 'd', 'e', 'a', 'b']);
2434+
///
2435+
/// let mut characters3 = vec!['a', 'b', 'c', 'd', 'e'];
2436+
/// characters3.extend_from_within(1..3);
2437+
/// assert_eq!(characters3, ['a', 'b', 'c', 'd', 'e', 'b', 'c']);
24152438
/// ```
24162439
#[cfg(not(no_global_oom_handling))]
24172440
#[stable(feature = "vec_extend_from_within", since = "1.53.0")]

0 commit comments

Comments
 (0)