From 592fc5a0e8666f4b29ba7f49cbf027a7d525ba69 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 20 Oct 2020 15:16:26 -0700 Subject: [PATCH] Add SmallVec::append method Fixes #236. --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8db5fa2..8f4ba72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -771,6 +771,24 @@ impl SmallVec { } } + /// Moves all the elements of `other` into `self`, leaving `other` empty. + /// + /// # Example + /// + /// ``` + /// # use smallvec::{SmallVec, smallvec}; + /// let mut v0: SmallVec<[u8; 16]> = smallvec![1, 2, 3]; + /// let mut v1: SmallVec<[u8; 32]> = smallvec![4, 5, 6]; + /// v0.append(&mut v1); + /// assert_eq!(*v0, [1, 2, 3, 4, 5, 6]); + /// assert_eq!(*v1, []); + /// ``` + pub fn append(&mut self, other: &mut SmallVec) + where B: Array + { + self.extend(other.drain(..)) + } + /// Re-allocate to set the capacity to `max(new_cap, inline_size())`. /// /// Panics if `new_cap` is less than the vector's length