]> git.lizzy.rs Git - rust.git/commitdiff
collections: Convert SliceConcatExt to use associated types
authorUlrik Sverdrup <root@localhost>
Tue, 5 May 2015 14:34:35 +0000 (16:34 +0200)
committerUlrik Sverdrup <root@localhost>
Tue, 5 May 2015 14:39:33 +0000 (16:39 +0200)
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.

src/libcollections/slice.rs
src/libcollections/str.rs

index 6622d8a9c40633a3b1a2bb374056d6cd0f69ec9c..3f9d6e64412a77bd2bed4ed8743498bb5f504aa6 100644 (file)
@@ -996,9 +996,13 @@ pub fn into_vec(self: Box<Self>) -> Vec<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
@@ -1011,7 +1015,7 @@ pub trait SliceConcatExt<T: ?Sized, U> {
     /// println!("{}", s); // prints "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.
     ///
@@ -1025,10 +1029,12 @@ pub trait SliceConcatExt<T: ?Sized, U> {
     /// println!("{}", s); // prints "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);
index db9f526a0f22e368459aacb92c48aba6493aa8f8..fd94b00a2dc4de5b039caaa6c19e9c87f782ae65 100644 (file)
@@ -83,7 +83,9 @@
 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();