Skip to content

Commit 28fb0f4

Browse files
authored
Auto merge of #237 - mbrubeck:append, r=jdm
Add SmallVec::append method Fixes #236.
2 parents caea701 + 592fc5a commit 28fb0f4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,24 @@ impl<A: Array> SmallVec<A> {
771771
}
772772
}
773773

774+
/// Moves all the elements of `other` into `self`, leaving `other` empty.
775+
///
776+
/// # Example
777+
///
778+
/// ```
779+
/// # use smallvec::{SmallVec, smallvec};
780+
/// let mut v0: SmallVec<[u8; 16]> = smallvec![1, 2, 3];
781+
/// let mut v1: SmallVec<[u8; 32]> = smallvec![4, 5, 6];
782+
/// v0.append(&mut v1);
783+
/// assert_eq!(*v0, [1, 2, 3, 4, 5, 6]);
784+
/// assert_eq!(*v1, []);
785+
/// ```
786+
pub fn append<B>(&mut self, other: &mut SmallVec<B>)
787+
where B: Array<Item = A::Item>
788+
{
789+
self.extend(other.drain(..))
790+
}
791+
774792
/// Re-allocate to set the capacity to `max(new_cap, inline_size())`.
775793
///
776794
/// Panics if `new_cap` is less than the vector's length

0 commit comments

Comments
 (0)