about summary refs log tree commit diff
path: root/src/libstd/vec.rs
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2014-03-30 23:53:26 -0400
committerDaniel Micay <danielmicay@gmail.com>2014-03-31 01:13:48 -0400
commitcbbc1fc843a0bea0191f66b76ff6fcc9005d7b0f (patch)
tree8ae67254c54ac66f5f74a1418e67326b39458d56 /src/libstd/vec.rs
parent612e22e417b41326b2060416892c7b16d921e20b (diff)
downloadrust-cbbc1fc843a0bea0191f66b76ff6fcc9005d7b0f.tar.gz
rust-cbbc1fc843a0bea0191f66b76ff6fcc9005d7b0f.zip
vec: convert `append` and `append_one` to methods
These were only free functions on `~[T]` because taking self by-value
used to be broken.
Diffstat (limited to 'src/libstd/vec.rs')
-rw-r--r--src/libstd/vec.rs64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 11fd2b8ee22..950c19bb4a3 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -166,6 +166,22 @@ impl<T> Vec<T> {
 }
 
 impl<T: Clone> Vec<T> {
+    /// Iterates over the `second` vector, copying each element and appending it to
+    /// the `first`. Afterwards, the `first` is then returned for use again.
+    ///
+    /// # Example
+    ///
+    /// ```rust
+    /// let vec = vec!(1, 2);
+    /// let vec = vec.append([3, 4]);
+    /// assert_eq!(vec, vec!(1, 2, 3, 4));
+    /// ```
+    #[inline]
+    pub fn append(mut self, second: &[T]) -> Vec<T> {
+        self.push_all(second);
+        self
+    }
+
     /// Constructs a `Vec` by cloning elements of a slice.
     ///
     /// # Example
@@ -518,6 +534,22 @@ impl<T> Vec<T> {
         }
     }
 
+    /// Appends one element to the vector provided. The vector itself is then
+    /// returned for use again.
+    ///
+    /// # Example
+    ///
+    /// ```rust
+    /// let vec = vec!(1, 2);
+    /// let vec = vec.append_one(3);
+    /// assert_eq!(vec, vec!(1, 2, 3));
+    /// ```
+    #[inline]
+    pub fn append_one(mut self, x: T) -> Vec<T> {
+        self.push(x);
+        self
+    }
+
     /// Shorten a vector, dropping excess elements.
     ///
     /// If `len` is greater than the vector's current length, this has no
@@ -1248,38 +1280,6 @@ impl<T> Vector<T> for Vec<T> {
     }
 }
 
-/// Iterates over the `second` vector, copying each element and appending it to
-/// the `first`. Afterwards, the `first` is then returned for use again.
-///
-/// # Example
-///
-/// ```rust
-/// let vec = vec!(1, 2);
-/// let vec = std::vec::append(vec, [3, 4]);
-/// assert_eq!(vec, vec!(1, 2, 3, 4));
-/// ```
-#[inline]
-pub fn append<T:Clone>(mut first: Vec<T>, second: &[T]) -> Vec<T> {
-    first.push_all(second);
-    first
-}
-
-/// Appends one element to the vector provided. The vector itself is then
-/// returned for use again.
-///
-/// # Example
-///
-/// ```rust
-/// let vec = vec!(1, 2);
-/// let vec = std::vec::append_one(vec, 3);
-/// assert_eq!(vec, vec!(1, 2, 3));
-/// ```
-#[inline]
-pub fn append_one<T>(mut lhs: Vec<T>, x: T) -> Vec<T> {
-    lhs.push(x);
-    lhs
-}
-
 #[unsafe_destructor]
 impl<T> Drop for Vec<T> {
     fn drop(&mut self) {