From 3e1add7051e49f4a5e53a50e2ba067702f9b9aa2 Mon Sep 17 00:00:00 2001 From: debris Date: Fri, 15 Jan 2016 19:51:48 +0100 Subject: [PATCH] flush macro --- src/common.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/common.rs b/src/common.rs index 7750d9ea5..3ec02ad9b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -35,7 +35,23 @@ macro_rules! xx { } } +#[macro_export] +macro_rules! flush { + ($($arg:tt)*) => ($crate::flush(format!("{}", format_args!($($arg)*)))); +} + +#[macro_export] +macro_rules! flushln { + ($fmt:expr) => (flush!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => (flush!(concat!($fmt, "\n"), $($arg)*)); +} + pub fn flush(s: String) { ::std::io::stdout().write(s.as_bytes()).unwrap(); ::std::io::stdout().flush().unwrap(); } + +#[test] +fn test_flush() { + flushln!("hello_world {:?}", 1); +}