]> git.lizzy.rs Git - rust.git/commitdiff
Add `impl Show for &Show`
authorAlex Crichton <alex@alexcrichton.com>
Mon, 30 Jun 2014 19:33:37 +0000 (12:33 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 30 Jun 2014 19:33:37 +0000 (12:33 -0700)
This makes printing a `Show` trait object much easier.

src/libcore/fmt/mod.rs
src/test/run-pass/ifmt.rs

index ff7d7827fbb8ef932c8ab949438d67eade40dcce..7b84c005db548667c25f635e76d14888138858b9 100644 (file)
@@ -518,6 +518,9 @@ fn fmt(&self, f: &mut Formatter) -> Result { secret_show(*self, f) }
 impl<'a, T: Show> Show for &'a mut T {
     fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
 }
+impl<'a> Show for &'a Show {
+    fn fmt(&self, f: &mut Formatter) -> Result { (*self).fmt(f) }
+}
 
 impl Bool for bool {
     fn fmt(&self, f: &mut Formatter) -> Result {
index 1258a498dacb4e4368918588176ebc2bfbf7be29..e349f91a309f7f301f1a4d04d6badff2948e16f0 100644 (file)
@@ -81,6 +81,9 @@ pub fn main() {
     t!(format!("{foo_bar}", foo_bar=1i), "1");
     t!(format!("{:d}", 5i + 5i), "10");
 
+    let a: &fmt::Show = &1i;
+    t!(format!("{}", a), "1");
+
     // Formatting strings and their arguments
     t!(format!("{:s}", "a"), "a");
     t!(format!("{:4s}", "a"), "a   ");