可通过 #[cfg(debug_assertions)]
和 #[cfg(not(debug_assertions))]
来控制
Reference: https://doc.rust-lang.org/reference/conditional-compilation.html#debug_assertions
fn main() {
#[cfg(not(debug_assertions))]
println!("release mode build");
#[cfg(debug_assertions)]
println!("debug mode build");
}
# 输出: release mode build
cargo r --release
# 输出: debug mode build
cargo r