is_debug/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::fmt::Display;

#[derive(Debug, PartialEq)]
pub enum BuildModel {
    Debug,
    Release,
}

pub const fn build_channel() -> BuildModel {
    if cfg!(debug_assertions) {
        return BuildModel::Debug;
    }
    BuildModel::Release
}

impl Display for BuildModel {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Debug => f.write_str("debug"),
            Self::Release => f.write_str("release"),
        }
    }
}

pub const fn is_debug() -> bool {
    matches!(build_channel(), BuildModel::Debug)
}

pub const fn is_release() -> bool {
    matches!(build_channel(), BuildModel::Release)
}