From 2305dc093a198b877c1ed14cd0da5112faf0146a Mon Sep 17 00:00:00 2001 From: Chris Wong Date: Sat, 12 Sep 2015 15:19:25 +1200 Subject: [PATCH] Add a blanket impl for &mut std::fmt::Write There is already a corresponding impl for `std::io::Write`. This change will make the two traits more consistent. --- src/libcore/fmt/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 32a5aeda195..db7e6d3006f 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -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. -- 2.44.0