flush macro

This commit is contained in:
debris 2016-01-15 19:51:48 +01:00
parent e096d75448
commit 3e1add7051
1 changed files with 16 additions and 0 deletions

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