Handle fallout for vector addition
Adding two vectors now results in a Vec<T> instead of a ~[T]. Implement Add on Vec<T>.
This commit is contained in:
parent
cc42b61936
commit
2a0dac6f58
4 changed files with 38 additions and 20 deletions
|
@ -22,7 +22,7 @@ use mem::{size_of, move_val_init};
|
|||
use mem;
|
||||
use num;
|
||||
use num::{CheckedMul, CheckedAdd};
|
||||
use ops::Drop;
|
||||
use ops::{Add, Drop};
|
||||
use option::{None, Option, Some, Expect};
|
||||
use ptr::RawPtr;
|
||||
use ptr;
|
||||
|
@ -1370,6 +1370,16 @@ impl<T> Vector<T> for Vec<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Clone, V: Vector<T>> Add<V, Vec<T>> for Vec<T> {
|
||||
#[inline]
|
||||
fn add(&self, rhs: &V) -> Vec<T> {
|
||||
let mut res = Vec::with_capacity(self.len() + rhs.as_slice().len());
|
||||
res.push_all(self.as_slice());
|
||||
res.push_all(rhs.as_slice());
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe_destructor]
|
||||
impl<T> Drop for Vec<T> {
|
||||
fn drop(&mut self) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue