Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SmallVec::append method #237

Merged
merged 1 commit into from Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/lib.rs
Expand Up @@ -771,6 +771,24 @@ impl<A: Array> SmallVec<A> {
}
}

/// 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<B>(&mut self, other: &mut SmallVec<B>)
where B: Array<Item = A::Item>
{
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
Expand Down