Conditional compilation


I'm looking for a way to compile some code in my debug build, but not in my release build. More specifically I would like a part of a function not to be compiled on release. In other word, something similar to C/C++ assert with NDEBUG define. I'm aware of conditionnal compilation

#[cfg(target_os = "macos")]

but from what I understand, it's function wise only (I don't want duplicated code), and it's not possible to create our own options.

Any help is appreciated !

#[cfg] do work on statements and blocks.

Do you mean that :

            #[cfg(target_os = "unix")]

would work inside a function ? And if true, is there an attribute to get the build type like : build_type = "debug" or others ? I could not find one here.

You can use

    println!("debug mode");

That's what I was looking for, many thanks !