Skip to content

Commit 7f71308

Browse files
committed
---
yaml --- r: 151744 b: refs/heads/try2 c: 00f9263 h: refs/heads/master v: v3
1 parent 9162b62 commit 7f71308

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 3c06a0328a3c6824ff7578a6da46e133e9399854
8+
refs/heads/try2: 00f9263914da3d18c556d7ebc3941f9638721ac2
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/io/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,42 @@ pub trait Writer {
964964
/// decide whether their stream needs to be buffered or not.
965965
fn flush(&mut self) -> IoResult<()> { Ok(()) }
966966

967+
/// Writes a formatted string into this writer, returning any error
968+
/// encountered.
969+
///
970+
/// This method is primarily used to interface with the `format_args!`
971+
/// macro, but it is rare that this should explicitly be called. The
972+
/// `write!` macro should be favored to invoke this method instead.
973+
///
974+
/// # Errors
975+
///
976+
/// This function will return any I/O error reported while formatting.
977+
fn write_fmt(&mut self, fmt: &fmt::Arguments) -> IoResult<()> {
978+
// Create a shim which translates a Writer to a FormatWriter and saves
979+
// off I/O errors. instead of discarding them
980+
struct Adaptor<'a, T> {
981+
inner: &'a mut T,
982+
error: IoResult<()>,
983+
}
984+
impl<'a, T: Writer> fmt::FormatWriter for Adaptor<'a, T> {
985+
fn write(&mut self, bytes: &[u8]) -> fmt::Result {
986+
match self.inner.write(bytes) {
987+
Ok(()) => Ok(()),
988+
Err(e) => {
989+
self.error = Err(e);
990+
Err(fmt::WriteError)
991+
}
992+
}
993+
}
994+
}
995+
996+
let mut output = Adaptor { inner: self, error: Ok(()) };
997+
match fmt::write(&mut output, fmt) {
998+
Ok(()) => Ok(()),
999+
Err(..) => output.error
1000+
}
1001+
}
1002+
9671003
/// Write a rust string into this sink.
9681004
///
9691005
/// The bytes written will be the UTF-8 encoded version of the input string.

0 commit comments

Comments
 (0)