Conditional Compilation if unoptimized

Hi,

Is there a cfg attribute or macro to compile a code section if we are unoptimized, in other words, exclude it if we are in release.

I’m thinking about an ideas like:

if cfg!(unoptimized) {
   println!("Configuration:{:?}",config);
}

Thanks

1 Like

Hi, you can use cfg!(debug_assertions), it’s what debug_assert!() uses. I don’t know if there is a more general flag.

1 Like

There’s no cfg for optimisations. There’s one for debug assertions that is abused to mean debug builds in general.

However, for printing stuff conditionally, it’s best to use the log crate. It has debug and trace macros that can be complied optionally.

2 Likes

Thanks concerning log you are right but in that case it’s at beginning before log is initialized.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.