]> git.lizzy.rs Git - rust.git/commitdiff
Add a blanket impl for &mut std::fmt::Write
authorChris Wong <lambda.fairy@gmail.com>
Sat, 12 Sep 2015 03:19:25 +0000 (15:19 +1200)
committerChris Wong <lambda.fairy@gmail.com>
Sat, 12 Sep 2015 23:42:42 +0000 (11:42 +1200)
There is already a corresponding impl for `std::io::Write`. This change
will make the two traits more consistent.

src/libcore/fmt/mod.rs

index 32a5aeda195ef8f0a058ad832d550d34fbc326b8..db7e6d3006f3f25f6bfb4a1a2fafb96edd76c089 100644 (file)
@@ -121,6 +121,21 @@ fn write_fmt(&mut self, args: Arguments) -> Result {
     }
 }
 
+#[stable(feature = "fmt_write_blanket_impl", since = "1.4.0")]
+impl<'a, W: Write + ?Sized> Write for &'a mut W {
+    fn write_str(&mut self, s: &str) -> Result {
+        (**self).write_str(s)
+    }
+
+    fn write_char(&mut self, c: char) -> Result {
+        (**self).write_char(c)
+    }
+
+    fn write_fmt(&mut self, args: Arguments) -> Result {
+        (**self).write_fmt(args)
+    }
+}
+
 /// A struct to represent both where to emit formatting strings to and how they
 /// should be formatted. A mutable version of this is passed to all formatting
 /// traits.