Skip to content

Commit

Permalink
std: Rewrite the write! and writeln! macros
Browse files Browse the repository at this point in the history
These are reimplemented using the new `core::fmt` module.
  • Loading branch information
alexcrichton committed May 16, 2014
1 parent 854d95f commit 8767093
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,27 @@ macro_rules! format_strbuf(
/// write!(&mut w, "formatted {}", "arguments");
/// ```
#[macro_export]
#[cfg(not(stage0))]
macro_rules! write(
($dst:expr, $($arg:tt)*) => ({
let dst: &mut ::std::io::Writer = $dst;
format_args!(|args| { ::std::fmt::write(dst, args) }, $($arg)*)
format_args_method!($dst, write_fmt, $($arg)*)
})
)
#[cfg(stage0)]
#[macro_export]
macro_rules! write(
($dst:expr, $($arg:tt)*) => ({
format_args!(|args| { $dst.write_fmt(args) }, $($arg)*)
})
)

/// Equivalent to the `write!` macro, except that a newline is appended after
/// the message is written.
#[macro_export]
macro_rules! writeln(
($dst:expr, $($arg:tt)*) => ({
let dst: &mut ::std::io::Writer = $dst;
format_args!(|args| { ::std::fmt::writeln(dst, args) }, $($arg)*)
($dst:expr, $fmt:expr $($arg:tt)*) => ({
format_args!(|args| { $dst.write_fmt(args) },
concat!($fmt, "\n") $($arg)*)
})
)

Expand Down

0 comments on commit 8767093

Please sign in to comment.