Returns the value of a configuration flag during compilation.
This can be used as an alternative to #[cfg]
attributes. The difference is that
cfg!
can be used in any expression position, while #[cfg]
can only be used on
statements and items.
Example
use std::cfg;
use std::time::Duration;
use std::thread::sleep;
when cfg!("debug") {
sleep(Duration::from_millis(100));
println!("program was built in debug mode, that's why it's so slow ;)");
} else {
println!("program was built in release mode and is blazing fast!");
}
Run this example