// // Copyright (C) <2026> // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . /* This file contains basic enums and structs to be used with stages. */ use std::collections::HashMap; #[derive(Debug, Clone)] pub enum ConfigValue { String(String), I64(i64), U64(u64), F64(f64), Bool(bool), Vector(Vec), Dictionary(HashMap), } #[derive(Debug, Clone)] pub struct StageResult { pub name: String, pub config: Option>, pub error: Option, } impl StageResult { pub fn new(name: &str) -> Self { Self { name: name.into(), config: None, error: None, } } pub fn add_error(mut self, ex: String) -> Self { self.error = Some(ex); self } pub fn add_val(mut self, val_name: &str, conf_val: ConfigValue) -> Self { match &mut self.config { Some(c) => { c.insert(val_name.into(), conf_val); } None => { self.config = Some(HashMap::from([(val_name.into(), conf_val)])); } } self } pub fn add_val_string(self, val_name: &str, v: String) -> Self { self.add_val(val_name, ConfigValue::String(v)) } pub fn add_val_bool(self, val_name: &str, v: bool) -> Self { self.add_val(val_name, ConfigValue::Bool(v)) } pub fn add_val_u64(self, val_name: &str, v: u64) -> Self { self.add_val(val_name, ConfigValue::U64(v)) } pub fn get_val(&self, val_name: &str) -> Option { let v = self .config .as_ref() .and_then(|hm| hm.get(val_name).cloned()); return v; } pub fn get_val_str(&self, val_name: &str) -> Option { match self.get_val(val_name) { Some(ConfigValue::String(v)) => Some(v), _ => None, } } pub fn get_val_bool(&self, val_name: &str) -> Option { match self.get_val(val_name) { Some(ConfigValue::Bool(v)) => Some(v), _ => None, } } } pub struct KiraConfig { pub config_trail: Vec, } impl Default for KiraConfig { fn default() -> Self { Self { config_trail: Vec::new(), } } } impl KiraConfig { pub fn get_stage(&self, name: &str) -> Option { self.config_trail .iter() .find(|v| v.name == name) .and_then(|v| Some(v.clone())) } pub fn pop_last(&mut self) -> Option { self.config_trail.pop() } pub fn push(&mut self, stage_result: StageResult) { self.config_trail.push(stage_result); } } #[derive(Debug, Clone)] pub enum StageAction { Back, None, Next(StageResult), Abort, }