]> git.lizzy.rs Git - rust.git/commitdiff
Implement Show for &mut [T]
authorThomas Backman <serenity@exscape.org>
Tue, 22 Apr 2014 17:41:02 +0000 (19:41 +0200)
committerThomas Backman <serenity@exscape.org>
Tue, 22 Apr 2014 17:41:02 +0000 (19:41 +0200)
src/libstd/slice.rs

index 6c55195e627286286da86cc4d07d20bae27c8ee7..620baabeef53988c5dd9c7017bf2a1935a1ca817 100644 (file)
@@ -2002,6 +2002,12 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+impl<'a, T: fmt::Show> fmt::Show for &'a mut [T] {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        self.as_slice().fmt(f)
+    }
+}
+
 impl<T: fmt::Show> fmt::Show for ~[T] {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         self.as_slice().fmt(f)
@@ -3408,6 +3414,12 @@ macro_rules! test_show_vec(
         test_show_vec!(~[1], "[1]".to_owned());
         test_show_vec!(~[1, 2, 3], "[1, 2, 3]".to_owned());
         test_show_vec!(~[~[], ~[1u], ~[1u, 1u]], "[[], [1], [1, 1]]".to_owned());
+
+        let empty_mut: &mut [int] = &mut[];
+        test_show_vec!(empty_mut, "[]".to_owned());
+        test_show_vec!(&mut[1], "[1]".to_owned());
+        test_show_vec!(&mut[1, 2, 3], "[1, 2, 3]".to_owned());
+        test_show_vec!(&mut[&mut[], &mut[1u], &mut[1u, 1u]], "[[], [1], [1, 1]]".to_owned());
     }
 
     #[test]