Merge pull request #55 from gavofyork/flush_macro

Flush macro
This commit is contained in:
Gav Wood 2016-01-16 13:32:38 +01:00
commit cd0db09e14

View File

@ -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) { pub fn flush(s: String) {
::std::io::stdout().write(s.as_bytes()).unwrap(); ::std::io::stdout().write(s.as_bytes()).unwrap();
::std::io::stdout().flush().unwrap(); ::std::io::stdout().flush().unwrap();
} }
#[test]
fn test_flush() {
flushln!("hello_world {:?}", 1);
}