diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-11 11:49:51 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-12 12:21:03 +1000 |
| commit | 96cd61ad034cc9e88ab6a7845c3480dbc1ea62f3 (patch) | |
| tree | 02a109c7703430ff9595c631e3ba4621c0374f1c /src/libstd/vec.rs | |
| parent | e06579bc0935ed1dcbddef41bc1b6a8850a2059c (diff) | |
| download | rust-96cd61ad034cc9e88ab6a7845c3480dbc1ea62f3.tar.gz rust-96cd61ad034cc9e88ab6a7845c3480dbc1ea62f3.zip | |
std: convert {vec,str}::to_owned to methods.
Diffstat (limited to 'src/libstd/vec.rs')
| -rw-r--r-- | src/libstd/vec.rs | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 19233c53348..52cb20458ea 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -171,11 +171,6 @@ pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> ~[T] { } } -/// Creates a new unique vector with the same contents as the slice -pub fn to_owned<T:Copy>(t: &[T]) -> ~[T] { - from_fn(t.len(), |i| t[i]) -} - /// Creates a new vector with a capacity of `capacity` pub fn with_capacity<T>(capacity: uint) -> ~[T] { let mut vec = ~[]; @@ -1787,7 +1782,7 @@ pub trait CopyableVector<T> { /// Extension methods for vectors impl<'self,T:Copy> CopyableVector<T> for &'self [T] { - /// Returns a copy of `v`. + /// Creates a new unique vector with the same contents as the slice #[inline] fn to_owned(&self) -> ~[T] { let mut result = ~[]; @@ -1796,7 +1791,6 @@ impl<'self,T:Copy> CopyableVector<T> for &'self [T] { result.push(copy *e); } result - } } @@ -3361,19 +3355,19 @@ mod tests { let mut results: ~[~[int]]; results = ~[]; - for each_permutation([]) |v| { results.push(to_owned(v)); } + for each_permutation([]) |v| { results.push(v.to_owned()); } assert_eq!(results, ~[~[]]); results = ~[]; - for each_permutation([7]) |v| { results.push(to_owned(v)); } + for each_permutation([7]) |v| { results.push(v.to_owned()); } assert_eq!(results, ~[~[7]]); results = ~[]; - for each_permutation([1,1]) |v| { results.push(to_owned(v)); } + for each_permutation([1,1]) |v| { results.push(v.to_owned()); } assert_eq!(results, ~[~[1,1],~[1,1]]); results = ~[]; - for each_permutation([5,2,0]) |v| { results.push(to_owned(v)); } + for each_permutation([5,2,0]) |v| { results.push(v.to_owned()); } assert!(results == ~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]); } |
