diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index d49463911e6..c4d9ef844eb 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1025,6 +1025,17 @@ pub trait SliceConcatExt { #[stable(feature = "rust1", since = "1.0.0")] fn concat(&self) -> Self::Output; + /// Flattens a slice of `T` into a single value `Self::Output`, placing a + /// given separator between each. + /// + /// # Examples + /// + /// ``` + /// assert_eq!(["hello", "world"].join(" "), "hello world"); + /// ``` + #[stable(feature = "rust1", since = "1.0.0")] + fn join(&self, sep: &T) -> Self::Output; + /// Flattens a slice of `T` into a single value `Self::Output`, placing a /// given separator between each. /// @@ -1034,6 +1045,7 @@ pub trait SliceConcatExt { /// assert_eq!(["hello", "world"].connect(" "), "hello world"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[deprecated(since = "1.3.0", reason = "renamed to join")] fn connect(&self, sep: &T) -> Self::Output; } @@ -1049,7 +1061,7 @@ impl> SliceConcatExt for [V] { result } - fn connect(&self, sep: &T) -> Vec { + fn join(&self, sep: &T) -> Vec { let size = self.iter().fold(0, |acc, v| acc + v.borrow().len()); let mut result = Vec::with_capacity(size + self.len()); let mut first = true; @@ -1059,6 +1071,10 @@ impl> SliceConcatExt for [V] { } result } + + fn connect(&self, sep: &T) -> Vec { + self.join(sep) + } } /// An iterator that yields the element swaps needed to produce diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 7e72ad1569a..7e4a219fc42 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -105,7 +105,7 @@ impl> SliceConcatExt for [S] { result } - fn connect(&self, sep: &str) -> String { + fn join(&self, sep: &str) -> String { if self.is_empty() { return String::new(); } @@ -132,6 +132,10 @@ impl> SliceConcatExt for [S] { } result } + + fn connect(&self, sep: &str) -> String { + self.join(sep) + } } /*