]> git.lizzy.rs Git - rust.git/commitdiff
Delegate ToStr implementation to Show for tuples
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>
Sun, 16 Feb 2014 07:27:46 +0000 (18:27 +1100)
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>
Sun, 16 Feb 2014 08:12:28 +0000 (19:12 +1100)
src/libstd/to_str.rs
src/libstd/tuple.rs

index 87d59f0979194841bb28f827fc42c7bf8a45fc91..ab14e9f566778664caad83207aa7744b54dbbf7b 100644 (file)
@@ -40,17 +40,6 @@ impl ToStr for () {
     fn to_str(&self) -> ~str { ~"()" }
 }
 
-impl<A:ToStr> ToStr for (A,) {
-    #[inline]
-    fn to_str(&self) -> ~str {
-        match *self {
-            (ref a,) => {
-                format!("({},)", (*a).to_str())
-            }
-        }
-    }
-}
-
 impl<A:ToStr+Hash+Eq, B:ToStr> ToStr for HashMap<A, B> {
     #[inline]
     fn to_str(&self) -> ~str {
@@ -91,36 +80,6 @@ fn to_str(&self) -> ~str {
     }
 }
 
-impl<A:ToStr,B:ToStr> ToStr for (A, B) {
-    #[inline]
-    fn to_str(&self) -> ~str {
-        // FIXME(#4653): this causes an llvm assertion
-        //let &(ref a, ref b) = self;
-        match *self {
-            (ref a, ref b) => {
-                format!("({}, {})", (*a).to_str(), (*b).to_str())
-            }
-        }
-    }
-}
-
-impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
-    #[inline]
-    fn to_str(&self) -> ~str {
-        // FIXME(#4653): this causes an llvm assertion
-        //let &(ref a, ref b, ref c) = self;
-        match *self {
-            (ref a, ref b, ref c) => {
-                format!("({}, {}, {})",
-                    (*a).to_str(),
-                    (*b).to_str(),
-                    (*c).to_str()
-                )
-            }
-        }
-    }
-}
-
 impl<'a,A:ToStr> ToStr for &'a [A] {
     #[inline]
     fn to_str(&self) -> ~str {
@@ -178,13 +137,6 @@ fn test_simple_types() {
         assert_eq!((~"hi").to_str(), ~"hi");
     }
 
-    #[test]
-    fn test_tuple_types() {
-        assert_eq!((1, 2).to_str(), ~"(1, 2)");
-        assert_eq!((~"a", ~"b", false).to_str(), ~"(a, b, false)");
-        assert_eq!(((), ((), 100)).to_str(), ~"((), ((), 100))");
-    }
-
     #[test]
     fn test_vectors() {
         let x: ~[int] = ~[];
index 9a1fda07ecd5e2f1626c835ade3f9fb74f9d3037..f2d1144f281ee378248dd48ec1649bf111720d9f 100644 (file)
@@ -17,6 +17,7 @@
 #[cfg(not(test))] use default::Default;
 use fmt;
 use result::{Ok, Err};
+use to_str::ToStr;
 
 /// Method extensions to pairs where both types satisfy the `Clone` bound
 pub trait CloneableTuple<T, U> {
@@ -179,6 +180,12 @@ fn default() -> ($($T,)+) {
                 }
             }
 
+            impl<$($T: fmt::Show),+> ToStr for ($($T,)+) {
+                fn to_str(&self) -> ~str {
+                    format!("{}", *self)
+                }
+            }
+
             impl<$($T: fmt::Show),+> fmt::Show for ($($T,)+) {
                 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                     write_tuple!(f.buf, $(self.$get_ref_fn()),+)