about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-06 11:56:15 +0000
committerbors <bors@rust-lang.org>2015-05-06 11:56:15 +0000
commit5a83fa271d9ea85bca163c26dc8896ac394976e4 (patch)
tree6485fb2a4a3d7966c16751301c97568f324db7a6
parentfc45fd99f5560c4ca731ba221ffaeb8ad4ba749c (diff)
parent2ca77f1c96f60b44c0d51d7d69046ad9a8532a46 (diff)
downloadrust-5a83fa271d9ea85bca163c26dc8896ac394976e4.tar.gz
rust-5a83fa271d9ea85bca163c26dc8896ac394976e4.zip
Auto merge of #25120 - bluss:sliceconcatext, r=alexcrichton
collections: Convert SliceConcatExt to use associated types

Coherence now allows this, we have `SliceConcatExt<T> for [V] where T: Sized + Clone` and` SliceConcatExt<str> for [S]`, these don't conflict because
str is never Sized.
-rw-r--r--src/libcollections/slice.rs16
-rw-r--r--src/libcollections/str.rs4
2 files changed, 14 insertions, 6 deletions
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs
index 729b0ebc3ce..8eb7995c422 100644
--- a/src/libcollections/slice.rs
+++ b/src/libcollections/slice.rs
@@ -996,9 +996,13 @@ impl<T> [T] {
 ////////////////////////////////////////////////////////////////////////////////
 // Extension traits for slices over specific kinds of data
 ////////////////////////////////////////////////////////////////////////////////
-#[unstable(feature = "collections", reason = "U should be an associated type")]
+#[unstable(feature = "collections", reason = "recently changed")]
 /// An extension trait for concatenating slices
-pub trait SliceConcatExt<T: ?Sized, U> {
+pub trait SliceConcatExt<T: ?Sized> {
+    #[unstable(feature = "collections", reason = "recently changed")]
+    /// The resulting type after concatenation
+    type Output;
+
     /// Flattens a slice of `T` into a single value `U`.
     ///
     /// # Examples
@@ -1007,7 +1011,7 @@ pub trait SliceConcatExt<T: ?Sized, U> {
     /// assert_eq!(["hello", "world"].concat(), "helloworld");
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
-    fn concat(&self) -> U;
+    fn concat(&self) -> Self::Output;
 
     /// Flattens a slice of `T` into a single value `U`, placing a given separator between each.
     ///
@@ -1017,10 +1021,12 @@ pub trait SliceConcatExt<T: ?Sized, U> {
     /// assert_eq!(["hello", "world"].connect(" "), "hello world");
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
-    fn connect(&self, sep: &T) -> U;
+    fn connect(&self, sep: &T) -> Self::Output;
 }
 
-impl<T: Clone, V: AsRef<[T]>> SliceConcatExt<T, Vec<T>> for [V] {
+impl<T: Clone, V: AsRef<[T]>> SliceConcatExt<T> for [V] {
+    type Output = Vec<T>;
+
     fn concat(&self) -> Vec<T> {
         let size = self.iter().fold(0, |acc, v| acc + v.as_ref().len());
         let mut result = Vec::with_capacity(size);
diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs
index 38431ab5bf1..da1b4dcddfc 100644
--- a/src/libcollections/str.rs
+++ b/src/libcollections/str.rs
@@ -83,7 +83,9 @@ pub use core::str::pattern;
 Section: Creating a string
 */
 
-impl<S: AsRef<str>> SliceConcatExt<str, String> for [S] {
+impl<S: AsRef<str>> SliceConcatExt<str> for [S] {
+    type Output = String;
+
     fn concat(&self) -> String {
         if self.is_empty() {
             return String::new();