导航

rust 条件编译 Debug Release

Posted on 2021-02-10 15:19  DotNet1010  阅读(871)  评论(0编辑  收藏  举报
#[cfg(debug_assertions)]
macro_rules! debug {
     () => (std::println!());
     ($($arg:tt)*) => ({
      println!($($arg)*);
     })
}
#[cfg(not(debug_assertions))]
macro_rules! debug {
    () => {};
    ($($arg:tt)*) => {};
}
fn main() {
    debug!("debug");
    debug!("debug {} {} {:?}", 1, 2, 3);
}

 可以不加 () => (std::println!());