How do I execute code based on the build type (release or debug)

⚓ Rust    📅 2025-08-20    👤 surdeus    👁️ 6      

surdeus

So I need to execute code based on the build type (release or debug).
For example I need to call function A for release binaries and function B for debug binaries.
Essentially I'm just logging variables and events.

So far this is what I have:

#[cfg(debug_assertions)]
{
    println!("Config: {:#?}", config);
    println!("-------");
}

I have seen that some sources suggest using the log crate.
I really don't want to add unnecessary dependencies just to solve a simple problem.
So I'm asking for help here :smiley: :+1:

3 posts - 3 participants

Read full topic

🏷️ Rust_feed