diff options
| author | Kevin Ballard <kevin@sb.org> | 2014-05-03 23:09:45 -0700 |
|---|---|---|
| committer | Kevin Ballard <kevin@sb.org> | 2014-05-08 12:06:22 -0700 |
| commit | 2a0dac6f58fb07d5fb6a4dfa94e10ddaa44315a7 (patch) | |
| tree | 141785eae7b1d17aa580e6cbe70dd5c3040aefdc /src/libstd/slice.rs | |
| parent | cc42b619362c344aacdb84ff00243b3e32168cad (diff) | |
| download | rust-2a0dac6f58fb07d5fb6a4dfa94e10ddaa44315a7.tar.gz rust-2a0dac6f58fb07d5fb6a4dfa94e10ddaa44315a7.zip | |
Handle fallout for vector addition
Adding two vectors now results in a Vec<T> instead of a ~[T]. Implement Add on Vec<T>.
Diffstat (limited to 'src/libstd/slice.rs')
| -rw-r--r-- | src/libstd/slice.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs index 42ffce56e87..d260ca46513 100644 --- a/src/libstd/slice.rs +++ b/src/libstd/slice.rs @@ -279,6 +279,26 @@ impl<T: Clone> Iterator<~[T]> for Permutations<T> { } } +#[cfg(not(test))] +impl<'a,T:Clone, V: Vector<T>> Add<V, Vec<T>> for &'a [T] { + #[inline] + fn add(&self, rhs: &V) -> Vec<T> { + let rhs = rhs.as_slice(); + let mut res = Vec::with_capacity(self.len() + rhs.len()); + res.push_all(*self); + res.push_all(rhs); + res + } +} + +#[cfg(not(test))] +impl<T:Clone, V: Vector<T>> Add<V, Vec<T>> for ~[T] { + #[inline] + fn add(&self, rhs: &V) -> Vec<T> { + self.as_slice() + rhs.as_slice() + } +} + /// Extension methods for vector slices with cloneable elements pub trait CloneableVector<T> { /// Copy `self` into a new owned vector |
