diff options
Diffstat (limited to 'src/libstd/at_vec.rs')
| -rw-r--r-- | src/libstd/at_vec.rs | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index dfd39af093d..13354e61284 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -11,9 +11,9 @@ //! Managed vectors use cast::transmute; +use clone::Clone; use container::Container; use iterator::IteratorUtil; -use kinds::Copy; use option::Option; use sys; use uint; @@ -90,10 +90,14 @@ pub fn build_sized_opt<A>(size: Option<uint>, /// Iterates over the `rhs` vector, copying each element and appending it to the /// `lhs`. Afterwards, the `lhs` is then returned for use again. #[inline] -pub fn append<T:Copy>(lhs: @[T], rhs: &[T]) -> @[T] { +pub fn append<T:Clone>(lhs: @[T], rhs: &[T]) -> @[T] { do build_sized(lhs.len() + rhs.len()) |push| { - for lhs.iter().advance |x| { push(copy *x); } - for uint::range(0, rhs.len()) |i| { push(copy rhs[i]); } + for lhs.iter().advance |x| { + push((*x).clone()); + } + for uint::range(0, rhs.len()) |i| { + push(rhs[i].clone()); + } } } @@ -126,10 +130,13 @@ pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> @[T] { * Creates an immutable vector of size `n_elts` and initializes the elements * to the value `t`. */ -pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> @[T] { +pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> @[T] { do build_sized(n_elts) |push| { let mut i: uint = 0u; - while i < n_elts { push(copy t); i += 1u; } + while i < n_elts { + push(t.clone()); + i += 1u; + } } } @@ -152,18 +159,24 @@ pub fn to_managed_consume<T>(v: ~[T]) -> @[T] { * Creates and initializes an immutable managed vector by copying all the * elements of a slice. */ -pub fn to_managed<T:Copy>(v: &[T]) -> @[T] { - from_fn(v.len(), |i| copy v[i]) +pub fn to_managed<T:Clone>(v: &[T]) -> @[T] { + from_fn(v.len(), |i| v[i].clone()) +} + +impl<T> Clone for @[T] { + fn clone(&self) -> @[T] { + *self + } } #[cfg(not(test))] pub mod traits { use at_vec::append; - use vec::Vector; - use kinds::Copy; + use clone::Clone; use ops::Add; + use vec::Vector; - impl<'self,T:Copy, V: Vector<T>> Add<V,@[T]> for @[T] { + impl<'self,T:Clone, V: Vector<T>> Add<V,@[T]> for @[T] { #[inline] fn add(&self, rhs: &V) -> @[T] { append(*self, rhs.as_slice()) |
