use std::fmt;
#[derive(Debug, Default, Eq, PartialEq, Clone, Copy)]
pub enum BuildMode {
#[default]
Debug,
Release,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum OptMode {
None,
Debug,
Full,
}
impl OptMode {
pub fn disable_optimization(&self) -> bool {
matches!(self, OptMode::None)
}
pub fn aggressive_function_inlining(&self) -> bool {
matches!(self, OptMode::Full)
}
}
impl fmt::Display for OptMode {
#[allow(clippy::use_debug)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self:?}")
}
}
#[derive(Debug, Eq, PartialEq)]
pub struct Config {
pub project_name: String,
pub project_description: String,
pub default_scoreboard_name: String,
pub build_mode: BuildMode,
pub opt_mode: OptMode,
}
impl Config {
pub fn update_build_mode(&mut self, build_mode: BuildMode) {
self.build_mode = build_mode;
self.opt_mode = build_mode.opt_mode();
}
}
impl BuildMode {
pub fn is_release(&self) -> bool {
matches!(self, BuildMode::Release)
}
pub fn is_debug(&self) -> bool {
matches!(self, BuildMode::Debug)
}
pub fn opt_mode(&self) -> OptMode {
match self {
BuildMode::Debug => OptMode::Debug,
BuildMode::Release => OptMode::Full,
}
}
}
impl Default for Config {
fn default() -> Self {
Config {
project_name: "debris_project".to_string(),
project_description: "A project generated by debris".to_string(),
default_scoreboard_name: "debris".to_string(),
build_mode: BuildMode::default(),
opt_mode: BuildMode::default().opt_mode(),
}
}
}