diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2014-12-27 23:57:43 +0200 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2014-12-27 23:57:43 +0200 |
| commit | 647e54d6d154e1a267e84c8ae9f1315e3f9b93fc (patch) | |
| tree | a25d8f7f938435e2dfcb2056353cbd4c3c3d8a55 /src/libstd/io | |
| parent | fc3f22bf2510dacb1fc4f5422b025a51bfda410e (diff) | |
| download | rust-647e54d6d154e1a267e84c8ae9f1315e3f9b93fc.tar.gz rust-647e54d6d154e1a267e84c8ae9f1315e3f9b93fc.zip | |
Fallout of changing format_args!(f, args) to f(format_args!(args)).
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/mod.rs | 42 | ||||
| -rw-r--r-- | src/libstd/io/stdio.rs | 20 |
2 files changed, 62 insertions, 0 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 233ad781093..b6f8bb25b65 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1017,6 +1017,48 @@ pub trait Writer { /// decide whether their stream needs to be buffered or not. fn flush(&mut self) -> IoResult<()> { Ok(()) } + // NOTE(stage0): Remove cfg after a snapshot + #[cfg(not(stage0))] + /// Writes a formatted string into this writer, returning any error + /// encountered. + /// + /// This method is primarily used to interface with the `format_args!` + /// macro, but it is rare that this should explicitly be called. The + /// `write!` macro should be favored to invoke this method instead. + /// + /// # Errors + /// + /// This function will return any I/O error reported while formatting. + fn write_fmt(&mut self, fmt: fmt::Arguments) -> IoResult<()> { + // Create a shim which translates a Writer to a FormatWriter and saves + // off I/O errors. instead of discarding them + struct Adaptor<'a, T:'a> { + inner: &'a mut T, + error: IoResult<()>, + } + + impl<'a, T: Writer> fmt::FormatWriter for Adaptor<'a, T> { + fn write(&mut self, bytes: &[u8]) -> fmt::Result { + match self.inner.write(bytes) { + Ok(()) => Ok(()), + Err(e) => { + self.error = Err(e); + Err(fmt::Error) + } + } + } + } + + let mut output = Adaptor { inner: self, error: Ok(()) }; + match fmt::write(&mut output, fmt) { + Ok(()) => Ok(()), + Err(..) => output.error + } + } + + + // NOTE(stage0): Remove method after a snapshot + #[cfg(stage0)] /// Writes a formatted string into this writer, returning any error /// encountered. /// diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index b7da57fed27..6bd721599f3 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -378,12 +378,32 @@ pub fn println(s: &str) { }) } +// NOTE(stage0): Remove cfg after a snapshot +#[cfg(not(stage0))] +/// Similar to `print`, but takes a `fmt::Arguments` structure to be compatible +/// with the `format_args!` macro. +pub fn print_args(fmt: fmt::Arguments) { + with_task_stdout(|io| write!(io, "{}", fmt)) +} + +// NOTE(stage0): Remove function after a snapshot +#[cfg(stage0)] /// Similar to `print`, but takes a `fmt::Arguments` structure to be compatible /// with the `format_args!` macro. pub fn print_args(fmt: &fmt::Arguments) { with_task_stdout(|io| write!(io, "{}", fmt)) } +// NOTE(stage0): Remove cfg after a snapshot +#[cfg(not(stage0))] +/// Similar to `println`, but takes a `fmt::Arguments` structure to be +/// compatible with the `format_args!` macro. +pub fn println_args(fmt: fmt::Arguments) { + with_task_stdout(|io| writeln!(io, "{}", fmt)) +} + +// NOTE(stage0): Remove function after a snapshot +#[cfg(stage0)] /// Similar to `println`, but takes a `fmt::Arguments` structure to be /// compatible with the `format_args!` macro. pub fn println_args(fmt: &fmt::Arguments) { |
