about summary refs log tree commit diff
path: root/src/libstd/fmt
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-04-30 21:02:13 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-05-07 08:14:54 -0700
commit92095d125ab4353a7bae002b893c2bd1bd06e379 (patch)
tree5df61620221a6f9afd352530ac80ba84eab45255 /src/libstd/fmt
parent1a989d67697fe33e51e7209511e89ba7faaba21d (diff)
downloadrust-92095d125ab4353a7bae002b893c2bd1bd06e379.tar.gz
rust-92095d125ab4353a7bae002b893c2bd1bd06e379.zip
core: Inherit the tuple module
Diffstat (limited to 'src/libstd/fmt')
-rw-r--r--src/libstd/fmt/mod.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs
index 7623da8734e..21121449205 100644
--- a/src/libstd/fmt/mod.rs
+++ b/src/libstd/fmt/mod.rs
@@ -1242,6 +1242,36 @@ impl<T> Show for *mut T {
     fn fmt(&self, f: &mut Formatter) -> Result { secret_pointer(self, f) }
 }
 
+macro_rules! peel(($name:ident, $($other:ident,)*) => (tuple!($($other,)*)))
+
+macro_rules! tuple (
+    () => ();
+    ( $($name:ident,)+ ) => (
+        impl<$($name:Show),*> Show for ($($name,)*) {
+            #[allow(uppercase_variables, dead_assignment)]
+            fn fmt(&self, f: &mut Formatter) -> Result {
+                try!(write!(f.buf, "("));
+                let ($(ref $name,)*) = *self;
+                let mut n = 0;
+                $(
+                    if n > 0 {
+                        try!(write!(f.buf, ", "));
+                    }
+                    try!(write!(f.buf, "{}", *$name));
+                    n += 1;
+                )*
+                if n == 1 {
+                    try!(write!(f.buf, ","));
+                }
+                write!(f.buf, ")")
+            }
+        }
+        peel!($($name,)*)
+    )
+)
+
+tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
+
 impl Show for Box<any::Any> {
     fn fmt(&self, f: &mut Formatter) -> Result { f.pad("Box<Any>") }
 }