Skip to content

Commit 3751d20

Browse files
Rollup merge of rust-lang#43455 - QuietMisdreavus:extend-spec-docs, r=steveklabnik
add a note to Vec's Extend<&T> impl about its slice specialization From the regular documentation view, it's not at all apparent that [this specialization](https://github.com/rust-lang/rust/blob/5669c9988f50788b5ab5dee2d4538519d4e5663d/src/liballoc/vec.rs#L1879-L1891) exists for `slice::Iter`. This adds a documentation blurb to the Extend impl itself to note that this optimization exists.
2 parents b583392 + 6e36769 commit 3751d20

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/liballoc/vec.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,12 @@ impl<T> Vec<T> {
19621962

19631963
}
19641964

1965+
/// Extend implementation that copies elements out of references before pushing them onto the Vec.
1966+
///
1967+
/// This implementation is specialized for slice iterators, where it uses [`copy_from_slice`] to
1968+
/// append the entire slice at once.
1969+
///
1970+
/// [`copy_from_slice`]: ../../std/primitive.slice.html#method.copy_from_slice
19651971
#[stable(feature = "extend_ref", since = "1.2.0")]
19661972
impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
19671973
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {

0 commit comments

Comments
 (0)