This commit is contained in:
Lokathor
2020-01-09 00:39:34 -07:00
parent 2a53070071
commit e50dfd5a5a
2 changed files with 29 additions and 1 deletions
+13 -1
View File
@@ -42,7 +42,19 @@ impl<A: Arrayish> IndexMut<usize> for ArrayishVec<A> {
}
impl<A: Arrayish> ArrayishVec<A> {
// TODO(Vec): append
#[inline]
pub fn append(&mut self, other: &mut Self) {
let final_len = self.len + other.len;
if final_len > A::CAPACITY {
panic!("ArrayishVec: overflow!");
}
let target_slice = &mut self.data.slice_mut()[self.len..final_len];
for (target_mut, app_mut) in target_slice.iter_mut().zip(other.deref_mut()) {
replace(target_mut, replace(app_mut, A::Item::default()));
}
self.len = final_len;
other.len = 0;
}
#[inline(always)]
#[must_use]
+16
View File
@@ -97,3 +97,19 @@ fn ArrayishVec_iteration() {
let av2: ArrayishVec<[i32; 4]> = av.clone().into_iter().collect();
assert_eq!(av, av2);
}
#[test]
fn ArrayishVec_append() {
let mut av: ArrayishVec<[i32; 10]> = Default::default();
av.push(1);
av.push(2);
av.push(3);
let mut av2: ArrayishVec<[i32; 10]> = Default::default();
av2.push(4);
av2.push(5);
av2.push(6);
//
av.append(&mut av2);
assert_eq!(av.as_slice(), &[1_i32, 2, 3, 4, 5, 6]);
assert_eq!(av2.as_slice(), &[]);
}