about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-31 02:11:34 -0700
committerbors <bors@rust-lang.org>2014-03-31 02:11:34 -0700
commit1c2ccf0503b7a74e94c8e57136a0878c6bcf30df (patch)
treeb97966317ad36940e4bdc1eb15aee335ac7c3c0d /src/libstd
parentabb616209d23f0883f4e96253c4233c29741fc7d (diff)
parentcbbc1fc843a0bea0191f66b76ff6fcc9005d7b0f (diff)
downloadrust-1c2ccf0503b7a74e94c8e57136a0878c6bcf30df.tar.gz
rust-1c2ccf0503b7a74e94c8e57136a0878c6bcf30df.zip
auto merge of #13221 : thestinger/rust/append, r=alexcrichton
These were only free functions on `~[T]` because taking self by-value
used to be broken.
Diffstat (limited to 'src/libstd')
-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 6265171f7d7..62fb52fccf9 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) {