diff options
| author | bors <bors@rust-lang.org> | 2015-06-10 21:02:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-06-10 21:02:08 +0000 |
| commit | db0c1cb13c9a1e68c09e2074b6d3a7b38122fb76 (patch) | |
| tree | ce750a4a1a1377aeadabec5990944fa2cf4a41d3 /src/libcore | |
| parent | ae8a3c92a77e9295a764fc98998245aa1e0336b1 (diff) | |
| parent | 63da18b269128c6594b0fa60064b187a9b5d0418 (diff) | |
| download | rust-db0c1cb13c9a1e68c09e2074b6d3a7b38122fb76.tar.gz rust-db0c1cb13c9a1e68c09e2074b6d3a7b38122fb76.zip | |
Auto merge of #24689 - SimonSapin:formatter-write-char, r=alexcrichton
This is the logical next step after #24661, but I’m less sure about this one. r? @alexcrichton
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/fmt/mod.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index ee1cab4076d..da4d24bdc7b 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -892,6 +892,21 @@ impl<'a> Formatter<'a> { } } +#[stable(since = "1.2.0", feature = "formatter_write")] +impl<'a> Write for Formatter<'a> { + fn write_str(&mut self, s: &str) -> Result { + self.buf.write_str(s) + } + + fn write_char(&mut self, c: char) -> Result { + self.buf.write_char(c) + } + + fn write_fmt(&mut self, args: Arguments) -> Result { + write(self.buf, args) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Display for Error { fn fmt(&self, f: &mut Formatter) -> Result { @@ -965,10 +980,7 @@ impl Debug for char { #[stable(feature = "rust1", since = "1.0.0")] impl Display for char { fn fmt(&self, f: &mut Formatter) -> Result { - let mut utf8 = [0; 4]; - let amt = self.encode_utf8(&mut utf8).unwrap_or(0); - let s: &str = unsafe { mem::transmute(&utf8[..amt]) }; - Display::fmt(s, f) + f.write_char(*self) } } |
